Patience Sorting

Distribution sort using card game patience rules.

Best O(n) Avg O(n log n) Worst O(n log n) Space O(n) Stable No In-place No Comparison-based

How it works

Distribution sort using card game patience rules.

Implementation

function patienceSort(arr) {
  const piles = [];
  for (const v of arr) {
    let placed = false;
    for (const pile of piles)
      if (pile[pile.length-1] >= v) { pile.push(v); placed = true; break; }
    if (!placed) piles.push([v]);
  }
  // Merge piles using a min-heap
}