#K55562. Longest Unique Subsequence

    ID: 30003 Type: Default 1000ms 256MiB

Longest Unique Subsequence

Longest Unique Subsequence

You are given an array of integers. Your task is to find the longest subsequence of numbers that appear exactly once in the array. The relative order of the elements should remain the same as in the input.

For example:

  • If the array is [4, 3, 4, 3, 7, 4, 3, 7, 3, 6], the number 6 is the only number that appears exactly once; hence, the answer is [6].
  • If the array is [1, 2, 2, 3, 1], then 3 is the only unique number and the answer is [3].
  • If the array is [10, 20, 30, 40, 50], all numbers are unique, and the entire array is the answer.

If there are no unique elements, output an empty line.

inputFormat

The input is given via standard input (stdin). The first line contains a single integer t representing the number of test cases. Each of the following t lines contains a test case. Each test case consists of a sequence of space-separated integers representing the array.

For example:

4
10 20 30 40 50
1 2 2 3 1
4 3 4 3 7 4 3 7 3 6
5 5 5 5 5

outputFormat

For each test case, output via standard output (stdout) a single line containing the subsequence of unique elements (elements that appear exactly once in the input), in their original order, separated by single spaces. If no such element exists, output an empty line.

For the input above, the expected output is:

10 20 30 40 50
3
6

## sample</p>
4
10 20 30 40 50
1 2 2 3 1
4 3 4 3 7 4 3 7 3 6
5 5 5 5 5
10 20 30 40 50

3 6

</p>