You are on page 1of 1

Java Full Stack Assessment Questions

Team A

Write a program in java to replace the duplicate elements in the given array with the
corresponding index value. if index values is already in that array elements, increase the index
until it becomes unique in that array elements .

5 7 8 5 4 7 6

For example scenario 1 : take 5

5 is duplicated at location 3 so replace 5 by its index 3 (but ensure that 3 is not available in
the array)

For example scenario 2 : take 7

7 is duplicated at location 5 so replaced it by the index 5, but 5 is already in the array so


increase index 5 by 1 that is 6 again check it in the array , 6 is available in the array so again
increase 6 by 1 so 7, again 7 is there so go for 8 , 8 is also there so that 9.

5 7 8 3 4 9 6

Note : -
1. Input should be taken from console in an array named “input” in the class
TestPerfect - main method
2. call and pass the input array to the makePerfectArray method, store the result
returned by the method in an array named “output” and should print input and
output array.
3. Create another class called PerfectArray with a static method named
makePerfectArray which accept an array as parameter and return the Perfect Array.
4. Use two different packages (package test and package perfect)

You might also like