← Questions

Oldest one-time visitor in a login stream

0
AmazonUberCodingLast asked Aug 2026

An online store wants to know which customers have visited only once. Every login is reported to your service as a username, in the order the logins happen.

Implement a class OneTimeVisitorTracker with:

  • login(user: str) -> None: record one login by user.
  • oldest_one_time_visitor() -> str | None: among all users who have logged in exactly once so far, return the one whose login came first. Return None if there is no such user.

A user who logs in a second time stops being a one-time visitor for good, no matter how many more times they log in.

Constraints

  • Up to 10^6 calls in total; usernames are non-empty strings and case-sensitive.
  • Aim for O(1) time per call.

Example 1

login("ana"); login("ben"); login("cy")
oldest_one_time_visitor()  -> "ana"
login("ana")
oldest_one_time_visitor()  -> "ben"

Example 2

login("ana"); login("ana"); login("ana")
oldest_one_time_visitor()  -> None
login("dee")
oldest_one_time_visitor()  -> "dee"
Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding