BETA
Rearrange an array such that arr[i] = i
Submissions: 927   Accuracy:

48.11%

  Difficulty: Easy
       

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

 

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

Contributor: Ankit Sharma
Author: Soul_xhacker


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