Skip to main content
Beginner~5 min · +40 XP

Bubble Sort Passes Needed

Practices: Bubble Sort

Problem

Bubble sort sweeps the array, swapping adjacent out-of-order pairs, with the sorted region growing from the right.

For the array [3, 1, 2, 4, 5, 6], how many COMPLETE passes are needed before the array is fully sorted (including the final clean pass that triggers the early exit)?

Examples

  • in: [1, 2, 3, 4]

    out: 1 pass

    Pass 1 finds no swaps → early exit after one clean sweep.

Constraints & conventions

  • A pass = one full sweep of the unsorted region. The early-exit pass counts.

Your answer

Solve the challenge to unlock the full approach and complexity analysis.