FastPrepKeep the First Key for Each Distinct Value
Problems/Keep the First Key for Each Distinct Value

Keep the First Key for Each Distinct Value

OneTrust logoOneTrust● EasyFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a OneTrust onsite interview for a full-time role. A frontend interview report asks to remove later object entries whose value repeats an earlier value. To work in any language, the insertion order is kept as parallel arrays of keys and values, and you return the keys that are kept.

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 <= 200000
  • keys are distinct nonempty strings
  • values contain signed 32-bit integers

More OneTrust interview questions

  • Kth Largest Element in an ArrayONSITE INTERVIEW · Seen Sep 2026
  • Merge IntervalsPHONE SCREEN · Seen Sep 2026
  • Summarize the Latest Event for Each DevicePHONE SCREEN · Seen Sep 2026

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
See OneTrust hiring insights
Saved
class Solution {
    public String[] keepFirstKeysByValue(String[] keys, int[] values) {
        // Write your code here.
    }

}
Checking account…