title: QuickSort implementation not working for large input
body: <p>Can anyone tell me why my quickSortHelper function doesn't solve for large input?</p>
  <pre><code>import java.util.*;
  
  class Program {
    public static int[] quickSort(int[] array) {
          // Write your code here.
          quickSortHelper(array, 0, array.length - 1);
          return array;
      }
  
      public static void quickSortHelper(int[] array, int l, int r){
          if(l &gt;= r){
              return;
          }
          int pivot = l;
          int leftIndex = l + 1;
          int rightIndex = r;
          while(rightIndex &gt;= leftIndex ){
              if(array[leftIndex] &gt; array[pivot] &amp;&amp; array[rightIndex] &lt; array[pivot]){
                  swap(leftIndex, rightIndex, array);
              }
              if(array[leftIndex] &lt;= array[pivot]){
                  leftIndex += 1;
              }
              if(array[rightIndex] &gt;= array[pivot]){
                  rightIndex -= 1;
              }
          }
          swap(pivot, rightIndex, array);
          boolean leftSubarrayIsSmaller = rightIndex - 1 - l &lt; r - (rightIndex + 1);
          if(leftSubarrayIsSmaller){
              quickSortHelper(array, rightIndex + 1, l);
              quickSortHelper(array, l, rightIndex - 1);
          }else{
              quickSortHelper(array, l, rightIndex - 1);
              quickSortHelper(array, rightIndex + 1, l);
          }
      }
  
      public static void swap(int i, int j, int[] array){
          int temp = array[j];
          array[j] = array[i];
          array[i] = temp;
      }
  }
  </code></pre>
  <p>Here's my test case, I think if I solve for this it will be an efficient implementation.</p>
  <pre><code>int[] array7 = {-4, 5, 10, 8, -10, -6, -4, -2, -5, 3, 5, -4, -5, -1, 1, 6, -7, -6, -7, 8};
  </code></pre>
  <p>The current result is as follows</p>
  <pre><code>[-10, -7, -6, -7, -6, -5, -4, -5, -4, 3, 5, -4, -2, -1, 1, 6, 8, 10, 5, 8]
  </code></pre>
  <p>As you can see, still not completely sorted. This does work for smaller input, as in less than 10 numbers.</p>
  <p>Any help would be highly appreciated!</p>
  <p>Cheers,</p>