title: My Array merge sorter does not work properly with odd number length of the array that includes some duplicate values
body: <p>My Array merge sorter does not work properly with odd number length of the array that includes some duplicate values. For example, for <code>int[] array = {1, 3, 15, 3, 7, 9, 8, 15, 0}</code> the result is <code>{0, 1, 3, 3, 7, 8, 0, 9, 15,}</code>. Can someone tell me where I am wrong?</p>
  
  <pre><code>public static void mergeSort(int[] inputArray) {
      int size = inputArray.length;
      if (size &lt; 2)
          return;
      int mid = size / 2;
      int leftSize = mid;
      int[] left = Arrays.copyOfRange(inputArray, 0, leftSize);
      int[] right = Arrays.copyOfRange(inputArray, leftSize, inputArray.length);
      mergeSort(left);
      mergeSort(right);
      merge(left, right, inputArray);
  }
  
  public static void merge(int[] left, int[] right, int[] arr) {
      int leftSize = left.length;
      int rightSize = right.length;
      int i = 0, j = 0, k = 0;
      while (i &lt; leftSize &amp;&amp; j &lt; rightSize) {
          if (left[i] &lt;= right[j]) {
              arr[k++] = left[i++];
          } else {
              arr[k++] = right[j++];
          }
      }
      while (i &lt; leftSize) {
          arr[k++] = left[i++];
      }
      while (j &lt; leftSize) {
          arr[k++] = right[j++];
      }
  }
  </code></pre>