Challenge: Sorting From 1 to n

Try solving the problem of sorting numbers from 1 to n.

Problem

You are given an array of length nn. It contains unique elements from 1 to nn. 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 70+ hands-on prep courses.