Last duplicate element in a sorted array
Submissions: 4450   Accuracy:

35.76%

  Difficulty: Basic   Marks: 1

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.

Input:
The first line of input contains an integer denoting the number of test cases. For each test case, the first line contains an integer denoting the size of array A followed by N-space separated integers denoting the elements of the array.

Output:
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.

Constraints:
1<=T<=100
1<=N<=50
1<=A[i]<=50

Example:
Input:

2
6
1 5 5 6 6 7
5
1 2 3 4 5
Output
4 6
-1

Explanation:
1.  Last duplicate element is 6 having index 4.
2. As no duplicate element exist, hence -1 is printed. 

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

Contributor: Vanshika
Author: Vanshika_pec


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.