Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

First Unique Value

Queuesmedium

Implement `firstUnique(arr)` returning the first value that appears exactly once, or `null` if none. (A queue of candidates is the classic streaming approach.)

Sample tests

Input: firstUnique([1,2,2,3])
Output: 1
Input: firstUnique([1,1,2,2])
Output: null

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Returning the first not-yet-repeated value before counting the whole input.

Learning resources

  • Wikipedia: Data structure
Approach & explanation (try first)

Counting then scanning in order finds the first unique value in O(n) time.

Loading...
⌘/Ctrl + Enter

Run your code to see results.