Given an array arr[] of positive integers, sort the array in nondecreasing…
PYQ Accenture Hiring Assessment 2025
Given an array arr[] of positive integers, sort the array in nondecreasing order using the insertion sort algorithm and print the sorted array.
Input format
The first line contains a single integer n — the number of elements in arr[].
The second line contains n space-separated integers arr[0], arr[1], …, arr[n-1].
Output format
Print the n elements of the sorted array in nondecreasing order, separated by single spaces, on one line.
Examples
Input:
5
4 1 3 9 7
Output:
1 3 4 7 9
Explanation: The sorted array is 1 3 4 7 9.Input:
10
10 9 8 7 6 5 4 3 2 1
Output:
1 2 3 4 5 6 7 8 9 10
Explanation: The sorted array is 1 2 3 4 5 6 7 8 9 10.Input:
3
4 1 9
Output:
1 4 9
Explanation: The sorted array is 1 4 9.
Constraints
1 ≤ n ≤ 1000
1 ≤ arr[i] ≤ 10000
Attempted by 4 students.
Sign up free to check your answer
Sign up freeLoading lesson…

