Easy · Arrays

Insertion sort

Given an integer array nums, sort it in place into non-decreasing order with insertion sort (insert each element into the sorted prefix before it); the function returns nothing.

Examples

Example 1

[5, 2, 8, 1, 9, 3]

Output: [1, 2, 3, 5, 8, 9]

Example 2

[7, 6, 5, 4, 3] · worst

Output: [3, 4, 5, 6, 7]

Rebuild it in the studio

Open every published interview problem, solution, scene, and memory room free, with no account.

More Arrays problems