AlgoFrames

Spot the bug: the scan stops early

Standard · Find the bug · about 8 min

This quick sort uses the Lomuto partition but returns unsorted arrays for some inputs. Click the line with the bug, then fix it.

Example 1

Input:

[[1,3,2]]

Output:

[1,2,3]

The buggy code returns [1, 3, 2].

Constraints

  • 0 ≤ nums.length ≤ 1,000

Learn the idea first: Quick sort: partitioning and pivots, a visual lesson.

More Quick sort: partitioning and pivots problems