#C14534. First Unique Element from Shifted Subarrays
First Unique Element from Shifted Subarrays
First Unique Element from Shifted Subarrays
You are given a list of integers. For each subarray formed by taking a suffix of the list (i.e. starting from index (i) for (0 \leq i < n)), find the first integer that has not appeared in any of the previous subarrays. In other words, while scanning the list from left to right, output each integer at its first appearance. Formally, if the input array is (A=[a_0, a_1, \ldots, a_{n-1}]), maintain a set (S) initially empty, and for each index (i) from (0) to (n-1), scan the subarray (A[i:]) and select the first element (a_j) (with (j \ge i)) such that (a_j \notin S). Add (a_j) to (S) and include it in the output. The final output is ({s_1, s_2, \ldots, s_k}) where each (s_i) is the unique integer encountered for the first time in order of appearance.
inputFormat
The input is given via standard input (stdin). The first line contains an integer (n) (the number of elements in the list). The second line contains (n) space-separated integers representing the list. For an empty list, (n=0) and the second line may be empty.
outputFormat
Output the resulting list of integers (the distinct elements in order of their first unique occurrence as defined above) to standard output (stdout). The integers should be printed in one line, separated by a single space. If the list is empty, output an empty line.## sample
7
3 4 4 3 5 6 6
3 4 5 6