Skip to the code
cf.
+10 XP

#16 First One-Time Visitor

easy

Your analytics tool records the user id of every page visit, in order, in visits. Marketing wants to know who came only once.

Write firstOneTimeVisitor(visits) that returns the first id (in visit order) that appears exactly once in visits. If every id appears more than once, or visits is empty, return null.

Example 1

Input: visits = ["u1","u2","u1","u3","u2"]
Output: "u3"

u1 and u2 came twice; u3 came once.

Example 2

Input: visits = ["a","a"]
Output: null

The only visitor came twice.

Constraints

  • 0 <= visits.length <= 10^5
  • Ids are non-empty strings.
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).