Challenge: Sorting From 1 to n
Try solving the problem of sorting numbers from 1 to n.
We'll cover the following
Problem
You are given an array of length . It contains unique elements from 1 to . You are required to sort the array elements. Missing elements will be placed at -1
.
Input
An integer array.
Output
A sorted array.
Sample input
array = { 8, 5, 6, 1, 9, 3, 2, 7, 4, 10 }
Sample output
array = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
Letās look at the illustration below to better understand the problem.
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.