Question
1) Given a list A of elements of length N , ranging from 1 to N . All elements may not be present in the
1) Given a listAof elements of lengthN, ranging from1 to N. All elements may not be present in the array. If the element is not present then there will be -1 present in the array. Rearrange the array such thatA[i] = iand if i is not present display -1 at that place.
Input Format:
The first line contains n numbers with each number separated by a space.
Output Format:
Print the elements of the list after the modification.
Example:
Input:
-1 -1 6 1 9 3 2 -1 4 -1
Output:
-1 1 2 3 4 -1 6 -1 -1 9
Explanation:
The modified list contains elements such that A[i] = i.
Test cases
input
3 1 4 2 5 0
Output
0 1 2 3 4 5
Input
2 1 3 4 -1
Output
-1 1 2 3 4
Input
4 7 -1 9 -1 5 3 -1 -1 -1
Output
-1 -1 -1 3 4 5 -1 7 -1 9
NOTE:
1.Input should be accepted from the user as many as he enter. User donotknow how many digits he is going to enter.
2. All the test cases should be satisfied
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started