Last seen array element
Submissions: 872   Accuracy:

36.42%

  Difficulty: Easy   Marks: 2

Given an array of N integers that might contain duplicates, find the element whose last appearance is earliest.

Input:
First line of input contains a single integer T denoting the number of test cases. First line of every test case has one number N denoting the length of the array and second line of every test case has N integers.

Output:
For each test case, print the required output.

Constraints:
1<=T<=100
1<=N<=10^3
1<=A[i]<=10^6

Example:
Input:

1
5
10 30 20 10 20
Output:
30

Explanation:
Below are indexes of last
appearances of all elements (0 based indexes)
10 last occurs at index 3
30 last occurs at index 1
20 last occurs at index 2
The element whose last appearance earliest
is 30.

 

 

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

Author: Striver


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.