#C14397. Remove Duplicates from a List

    ID: 44041 Type: Default 1000ms 256MiB

Remove Duplicates from a List

Remove Duplicates from a List

This problem requires you to remove duplicate integers from a list while preserving the original order. Given a list of integers (which may include both positive and negative values), your task is to return a new list that contains each number only once, keeping the order of their first appearance.

Input Format: The input consists of an integer n on the first line, representing the number of elements in the list. The second line contains n space-separated integers. If n = 0, the list is considered empty.

Output Format: Output the list after removing duplicates. The elements should be printed in order, separated by a single space. If the resulting list is empty, output an empty line.

The underlying algorithm should operate in \(O(n)\) time by scanning the list and utilizing an auxiliary data structure to track seen elements.

inputFormat

The input begins with an integer n indicating the number of elements in the list, followed by a line with n space-separated integers.

Example:

5
1 2 3 4 5

outputFormat

Print the list after removing duplicates while preserving the order. The output should have the numbers separated by a single space.

Example:

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

</p>