Spot the bug: the first cell
Standard · Find the bug · about 6 min
This insertion sort returns a wrong order for some inputs. Click the line with the bug, then fix it.
Example 1
Input:
[[2,5,8,1]]
Output:
[1,2,5,8]
The buggy code returns [2, 1, 5, 8].
Constraints
- 0 ≤ nums.length ≤ 1,000
Learn the idea first: Insertion sort, a visual lesson.
More Insertion sort problems
- State after inserting the 4th element Warm-up
- Implement insertion sort Standard
- Count the shifts Standard
- Insertion sort on a linked list Challenge