Find Duplicate Elements
Given an array of integers, return the distinct values that appear more than once. Each repeated value must be reported exactly once, regardless of how many…
Given an array of integers, return the distinct values that appear more than once. Each repeated value must be reported exactly once, regardless of how many times it occurs. List values in the order in which a left-to-right scan reaches each value's second occurrence. If no value repeats, the result is empty.
- `1 <= arr.length <= 10^4` - `-10^9 <= arr[i] <= 10^9` - The interactive visualizer accepts at most 12 values; longer valid judge inputs are execution-only. - Each duplicated value appears in the result exactly once. - Order the result by the index of each value's second occurrence.
Example 1: input arr = [1, 2, 3, 2, 4, 3]; output [2, 3]. 2 appears at indices 1 and 3; 3 appears at indices 2 and 5. Each is reported once.
Example 2: input arr = [4, 4, 4, 4]; output [4]. 4 repeats but is listed only once even though it appears four times.
Example 3: input arr = [1, 2, 3, 4]; output []. Every value is distinct, so there are no duplicates.
Category: Arrays. Topic: arrays. Difficulty: Easy. Patterns: hashing.