Timer is Running

Rearrange an array such that arr[i] = i
##### Submissions: 5285   Accuracy: 49.98%   Difficulty: Easy   Marks: 2

Given an array of size N that has elements ranging from 0 to N-1. All elements may not be present in the array. If element is not present then there will be -1 present

in the array. Rearrange the array such that A[i] = i, and if i is not present, display -1 at that place.

Input:
The first line of the input contains a single integer T, denoting the number of test cases. Then T test case follows. Each test case contains 2 lines:-
The size of the array N
Elements of the array separated by spaces

Output:
For each testcase, print the modified array.

Constraints:
1<=T<=100
1<=N<=1000
0<=A[i]<=N-1

Example:

Input:
2
10
-1 -1 6 1 9 3 2 -1 4 -1
20
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

Output:
-1 1 2 3 4 -1 6 -1 -1 9
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

Explanation:
Test Case 1:

In range 0 to 9, all except 0, 5, 7 and 8 are present. Hence, we print -1 instead of them.
Test Case 2:
All elements are present in range 0 to 19. Hence, we have arr[i] = i for all values of i in the output.

#### ** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Ankit Sharma
Author: Soul_xhacker

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.