P16327 [GeeksforGeeks] Last seen array element1501
普及-
题目描述

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

Example 1:
Input : arr[] = {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 4 The element whose
last appearance earliest is 30.

Example 2:
Input : arr[] = {10, 20, 30, 40, 10}
Output : 20
Your Task:
This is a function problem. The input is already taken care of by the driver code. You only need to complete the function lastSeenElement() that takes an array (arr), sizeOfArray (n), and returns the element whose last appearance is earliest. The driver code takes care of the printing.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(N).
Constraints:
1<=N<=10^{5}
1<=arr[i]<=10^{6}

输入格式

见题面

输出格式

见题面

样例输入
arr[] = {10, 30, 20, 10, 20}
样例输出
30