Keep the First Key for Each Distinct Value
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