Bingo Sort

Selection sort adapted for duplicates.

Best O(n+k) Avg O(n^2) Worst O(n^2) Space O(1) Stable No In-place Yes Comparison-based

How it works

Selection sort adapted for duplicates.

Implementation

function bingoSort(arr) {
  let max = Math.max(...arr);
  let nextMax, idx = arr.length - 1;
  while (idx > 0) {
    nextMax = arr[0];
    for (let i = 1; i <= idx; i++) {
      if (arr[i] === max) {
        [arr[i], arr[idx]] = [arr[idx], arr[i]]; idx--;
      } else if (arr[i] > nextMax) nextMax = arr[i];
    }
    max = nextMax;
  }
}