Multiple duplicates
Input
arr = [3, 1, 2, 3, 2]
Output
[3, 2]
3 becomes a duplicate when the second 3 is seen, then 2 becomes a duplicate when the second 2 is seen. Order: [3, 2].
Full lesson preview
Find elements that appear more than once using a frequency map and return them in first-duplicate order.
Problem statement
Task
Examples
Input
arr = [3, 1, 2, 3, 2]
Output
[3, 2]
3 becomes a duplicate when the second 3 is seen, then 2 becomes a duplicate when the second 2 is seen. Order: [3, 2].
Input format
Output format
Constraints
Samples
Input
arr = [1, 1, 1, 2]
Output
[1]
1 becomes a duplicate at the second 1, but subsequent repeats are not added again.