#K4301. Remove Duplicates from a List
Remove Duplicates from a List
Remove Duplicates from a List
You are given an integer \( n \) and a list of \( n \) integers. Your task is to remove duplicate values from the list while preserving the order of their first occurrence.
Example: For the list [4, 3, 2, 3, 4, 1, 1, 2], the output should be [4, 3, 2, 1] because although there are duplicates, only the first occurrence of each element is kept.
Input/Output Format: The input is read from stdin
and the output should be written to stdout
. The first line of input contains an integer \( n \), and the second line contains \( n \) space-separated integers. The output should be a single line of space-separated integers representing the list after duplicates have been removed.
inputFormat
The input consists of two lines:
- The first line is a single integer \( n \) which represents the number of integers.
- The second line contains \( n \) space-separated integers.
outputFormat
Output a single line of space-separated integers after removing duplicates while preserving the order of their first appearance. If the input list is empty (i.e., \( n = 0 \)), output an empty line.
## sample5
1 2 3 4 5
1 2 3 4 5