Stable quicksort from hackerrank challenge