#C13113. Remove Duplicates and Track Removed Elements
Remove Duplicates and Track Removed Elements
Remove Duplicates and Track Removed Elements
You are given a list of integers. Your task is to perform two operations:
- Remove duplicate elements from the list while preserving the order of their first occurrence.
- Determine which elements were removed and output each removed element along with its original index in the input list.
If the resulting list after duplicate removal is empty, output None
on the first line. Similarly, if no elements were removed, output None
on the second line.
Note: The indices are 0-based. For each element that is a duplicate (i.e. not the first occurrence), output a pair consisting of the element and its original index. The order of these pairs should follow the order in which the duplicates appear in the input.
For example, given the input:
9 1 2 3 2 4 5 3 4 6
The list after removing duplicates is:
1 2 3 4 5 6
The removed elements along with their original indices are:
2 3 3 6 4 7
where 2 at index 3, 3 at index 6, and 4 at index 7 were removed.
inputFormat
The input is given via standard input (stdin) and consists of two parts:
- The first line contains an integer n representing the number of elements in the list.
- If n > 0, the second line contains n space-separated integers.
If n is 0, then there will be no second line.
outputFormat
The output should be printed to standard output (stdout) in two lines:
- The first line contains the list after removing duplicates (preserving the original order), with each number separated by a space. If the list is empty, output
None
. - The second line contains the removed duplicate elements along with their original indices. Each pair is printed as two space-separated numbers (first the value then the index). The pairs are concatenated with a space in between. If no elements were removed, output
None
.
9
1 2 3 2 4 5 3 4 6
1 2 3 4 5 6
2 3 3 6 4 7
</p>