title: Wrong output while merging sorted arrays of equal length
body: <p>I'm trying to merge 2 sorted arrays of equal length. However, I'm not getting the desired output.
  Here is my code:</p>
  <pre><code>    public static int[] mergeSorted(int[] arr1, int[] arr2){
          int n = arr2.length;
  
          int[] ans = new int[2*n];
  
          int k = 0;
          int i = 0;
          int j = 0;
  
          while(i &lt; n &amp;&amp; j &lt; n){
              if(arr1[i] &lt;= arr2[j]){
                  ans[k] = arr1[i];
                  i++;
              }
              else{
                  ans[k] = arr2[j];
                  j++;
              }
              k++;
          }
  
          while(i &lt; n){
              ans[k] = arr1[i];
              k++;
              i++;
          }
  
          while(j &lt; n){
              ans[k] = arr2[j];
              k++;
              j++;
          }
  
  
          return ans;
      }
  
  
      public static void main(String[] args){
          int[] arr1 = new int[]{1, 3, 5, 100, 34, 29};
          int[] arr2 = new int[]{2, 4, 6, 9, 13, 300};
  
          int[] ans = mergeSorted(arr1, arr2);
  
          for(int el : ans)
              System.out.print(el + &quot; &quot;);
      }
  </code></pre>
  <p>Output:</p>
  <p>1 2 3 4 5 6 9 13 100 34 29 300</p>
  <p>Clearly, this is not correct. However, this code works for smaller inputs. Where am I going wrong?</p>
  <p>EDIT: Test cases were wrong as they were not sorted. Code was fine.</p>