Given a sorted array with duplicate elements and we have to find the index of last duplicate element and print index of it and also print the duplicate element.
The first line of input contains an integer T denoting the number of test cases. For each test case, the first line contains an integer N denoting the size of array A followed by N-space separated integers denoting the elements of the array.
For each test case, the output is two integers denoting the last index of the duplicate element and that duplicate element respectively and if no duplicate element occurs print -1.
1 5 5 6 6 7
1 2 3 4 5
1. Last duplicate element is 6 having index 4.
2. As no duplicate element exist, hence -1 is printed.
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.