#C12292. Remove Duplicates from a List

    ID: 41703 Type: Default 1000ms 256MiB

Remove Duplicates from a List

Remove Duplicates from a List

Given a list of integers, remove the duplicate elements while maintaining the order of their first occurrence. You must not use extra space for another array (although using a small auxiliary data structure for checking duplicates is allowed for this problem).

Note: The removal should be conceptually done in-place, but for the purpose of input/output, you will receive a list and output the list after removing duplicates.

The problem can be mathematically interpreted as follows: Given a sequence \(a_1, a_2, \dots, a_n\), produce a sequence \(b_1, b_2, \dots, b_k\) such that:

[ b_j = a_{i_j} \quad \text{with} \quad i_1 < i_2 < \cdots < i_k, \quad \text{and} \quad b_1, b_2, \dots, b_k \text{ are all unique.} ]

Your task is to implement a solution that reads an integer \(n\) (the number of elements), followed by \(n\) integers, and then outputs the list of unique integers separated by spaces.

inputFormat

The first line of input contains an integer \(n\) representing the number of elements in the list. The second line contains \(n\) space-separated integers.

Constraints:

  • \(0 \leq n \leq 10^5\)
  • The list elements can be any integer within the 32-bit signed integer range.

outputFormat

Output a single line containing the list of unique integers in their original order, separated by a single space. If the list is empty, output an empty line.

## sample
8
1 2 3 1 2 4 5 3
1 2 3 4 5