Find Duplicate Element Pairs
Updated
Problem statement
You are given ids.length elements. Element i has the unique identifier ids[i] and exactly three property values in properties[i].
Two distinct elements form a duplicate pair when they share at least one identical property value anywhere among their three properties. Duplicate pairing is direct: if element a matches b and b matches c, that chain alone does not make a and c a duplicate pair.
Return every duplicate identifier pair exactly once. Within each pair, place the earlier input element first. Order the returned pairs by the earlier input index and then by the later input index.
Property comparison is exact and case-sensitive. Repeating one property value inside an element does not duplicate an output pair.
Function
findDuplicatePairs(ids: String[], properties: String[][]) → String[][]Examples
Example 1
ids = ["id1","id2","id3"]properties = [["p1","p2","p3"],["p1","p6","p5"],["p3","p7","p8"]]return = [["id1","id2"],["id1","id3"]]id1 shares p1 with id2 and p3 with id3. The remaining pair shares no property.
Example 2
ids = ["a","b","c"]properties = [["x","p","q"],["x","y","r"],["y","s","t"]]return = [["a","b"],["b","c"]]a matches b through x, and b matches c through y. The chain does not create an a-c pair.
Example 3
ids = ["left","right"]properties = [["a","b","c"],["d","e","f"]]return = []The two elements share no property value, so there are no duplicate pairs.
Constraints
1 <= ids.length = properties.length <= 2000.- Every identifier is unique.
properties[i].length = 3.- Identifiers and property values are non-empty strings of at most
30printable ASCII characters. - Property comparison is case-sensitive.
More Google Onsite Interview questions
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
- Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
- Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Longest Consecutive Login StreakAmazon · ONSITE INTERVIEW
- Group AnagramsMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Deep Merge with a Conflict ResolverAutodesk · ONSITE INTERVIEWAutodesk interview questions
- Group Duplicate Files by ContentPostman · ONSITE INTERVIEWPostman interview questions
- Group AnagramsGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
- Group AnagramsMotive · PHONE SCREEN · ONSITE INTERVIEWMotive interview questions
- Group AnagramsBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Group AnagramsExpedia · ONSITE INTERVIEWExpedia interview questions
- Group AnagramsAkuna Capital · ONSITE INTERVIEWAkuna Capital interview questions
- Group Anagram StringsLondon Stock Exchange · ONSITE INTERVIEWLondon Stock Exchange interview questions