Keep the First Key for Each Distinct Value
Updated
Problem statement
Two equal-length arrays describe an insertion-ordered object: keys[i] is paired with values[i]. Remove every later entry whose value has already appeared, and return the retained keys in their original order.
Function
keepFirstKeysByValue(keys: String[], values: int[]) → String[]Examples
Example 1
keys = ["a","b","c","d"]values = [1,2,3,1]return = ["a","b","c"]The later key d repeats value one, so only the first key for that value remains.
Example 2
keys = ["a","b","c"]values = [1,1,1]return = ["a"]All entries share one value, so the first key is the only retained key.
Constraints
1 <= keys.length == values.length <= 200000keys are distinct nonempty stringsvalues contain signed 32-bit integers
More OneTrust interview questions
Similar questions at other companies
- Count Distinct Pairs With Sum KeBay · ONSITE INTERVIEWeBay interview questions
- List the Key and Value of Every Map EntryNewgen Software · ONSITE INTERVIEW
- Pizza Price CalculatorMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Cross-Day User Trust ScoresAffirm · PHONE SCREEN · ONSITE INTERVIEWAffirm interview questions
- Map and Accumulate Learning QueriesPalantir · ONSITE INTERVIEWPalantir interview questions
- Filter Pins by Excluded IDsPinterest · ONSITE INTERVIEWPinterest interview questions
- Best Average Student ScoreGoldman Sachs · PHONE SCREEN · ONSITE INTERVIEWGoldman Sachs interview questions
- Longest Dictionary Word from Nine LettersGoogle · ONSITE INTERVIEWGoogle interview questions
- Two SumOptimus Information · ONSITE INTERVIEWOptimus Information interview questions
- Two Positions That Add Up to a TargetDocuSign · PHONE SCREEN · ONSITE INTERVIEWDocuSign interview questions