Distinct Duplicate Values
Updated
Problem statement
Given an integer array data, return every distinct value that appears at least twice.
Return each duplicate value exactly once, ordered by the position of its first occurrence in data. If no value is duplicated, return an empty array.
Function
findDuplicateValues(data: int[]) → int[]Examples
Example 1
data = [4,2,4,3,2,4]return = [4,2]Values 4 and 2 both occur more than once. The first 4 appears before the first 2.
Example 2
data = [1,2,3,4]return = []Every value appears exactly once.
Example 3
data = [7,7,7,7]return = [7]The repeated value is returned only once regardless of how many times it appears.
Constraints
1 <= data.length <= 100000.-10^9 <= data[i] <= 10^9.
Source note: Author-written prompt excerpt retained for source fidelity.
Similar questions at other companies
- Best Average Student ScoreGoldman Sachs · PHONE SCREEN · ONSITE INTERVIEWGoldman Sachs interview questions
- Logger Rate LimiterGoogle · PHONE SCREENGoogle interview questions
- Merchant Payout Reserve CalculatorStripe · PHONE SCREENStripe interview questions
- Price CheckBlue Origin · PHONE SCREEN
- Majority ElementByteDance · PHONE SCREENByteDance interview questions
- Detect a Straight FlushTemu · PHONE SCREENTemu interview questions
- Recommend Films from Viewers Who Watched Everything You DidBloomberg LP · PHONE SCREENBloomberg LP interview questions
- Find Unique ElementsCisco · PHONE SCREENCisco interview questions
- Shared Courses for Every Pair of StudentsCrunchyroll · PHONE SCREENCrunchyroll interview questions
- Two SumAmazon · OA · PHONE SCREEN