Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource


Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource


Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.


Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.


<img src="" alt="">

<li>Select last number in the array call pivot.</li>
<img src="" alt="">
  Rearrange the list such that all the elements greater than of pivot are towards the right side of pivot.  All the elements lesser than the pivot will be towards the left side.  All the re-arrangements happen in the original array in-place.
<img src="" alt="">


                img {



                // Space complexity is O(1) (inplace partition and sorting no extra arrayay creation)
// Time complexity is O(n log (n))
// Very optimized

function quickSort(array) {
  let startIdx = 0;
  let endIdx = array.length-1;
  performQuickSort(array, 0, endIdx);

function performQuickSort(array, startIdx, endIdx) {
   if (startIdx < endIdx) {
    const partitionIdx = partition(array, startIdx, endIdx);
    performQuickSort(array, startIdx, partitionIdx - 1);
    performQuickSort(array, partitionIdx + 1, endIdx);

function partition(array, startIdx, endIdx) {
  const pivot = array[endIdx];
  let partitionIdx = startIdx;
  for (let idx = startIdx; idx < endIdx; idx++) {
    if (array[idx] <= pivot) {
      // all the elmeents lesser than pivot will be left of partitionIdx.
      swap(idx, partitionIdx, array); // Swap pivot with element at partition index. 
  swap(partitionIdx, endIdx, array);

  return partitionIdx;

function swap(idx1, idx2, array) {
  if(idx1===idx2) return;
  let temp = array[idx1];
  array[idx1] = array[idx2];
  array[idx2] = temp;

// unit tests
// do not modify the below code
describe('quickSort', function() {
  it('quicksort an arrayay', () => {
    const input = [7,6,5,4,3,2,1,0];
    const answer = quickSort(input);

   it('quicksort an arrayay', () => {
    const input = [7,2,1,6,8,5,3,4];
    const answer = quickSort(input);