Practice
Insertion Sort an Array
2025/May/June·Variant 2
MEDIUMAlgorithms
Sort 6 integers into ascending order using insertion sort — build up a sorted section on the left of the array, inserting each new element into its correct position.
Input: 6 integers. Output: The sorted array, one value per line.
Example:
Input: 5
3
8
4
2
7
Output: 2
3
4
5
7
8
Premium is coming soon. All grading features are currently unlocked.
Sample Test Cases
Test 1: Mixed values
Inputs: 5, 3, 8, 4, 2, 7
Expected: 2
3
4
5
7
8
Test 2: Already sorted
Inputs: 1, 2, 3, 4, 5, 6
Expected: 1
2
3
4
5
6