title: Why the following Java makeBricks solution fails?
body: <p>Can anyone help me to correct the solution for the following codingbat question? Thanks in advance.</p>
  
  <p>I am getting <code>OK</code> for all the test cases except for the unknown <code>"Other Tests"</code>.</p>
  
  <p><strong>Specification:</strong></p>
  
  <p>We want to make a row of bricks that is goal inches long. We have a number of small bricks (1 inch each) and big bricks (5 inches each). Return true if it is possible to make the goal by choosing from the given bricks. </p>
  
  <p><strong>Code Snippet:</strong></p>
  
  <pre><code>public boolean makeBricks(int small, int big, int goal) {
    if (goal == 0) return true;
  
    if (goal &lt; big * 5) {
      goal = goal - small; //Use all the small bricks each of inch 1
      while (goal &gt; 0) {
        goal = goal - 5;
        --big;
        if (big == 0) {
          break;
        }
      }
      return (goal == 0);
    }
    else {
      goal = goal - (big * 5); //Use all the big bricks each of inch 5
      while (goal &gt; 0) {
        goal = goal - 1;
        --small;
        if (small == 0) {
          break;
        }
      }
      return (goal == 0);
    }
  }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/Wptpx.png" alt="enter image description here"></p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>After working hard I found the solution which works for all the test cases. It is </p>
  
  <pre><code>  return ((goal &lt;= small + big * 5) &amp;&amp; goal % 5 &lt;= small);
  </code></pre>
  
  <p>But, just for the sake of curiosity I want to know why the above code snippet doesn't work for every case. Any help would be greatly appreciated.</p>