FastPrepFirst User to Log In Exactly Once
Problems/First User to Log In Exactly Once

First User to Log In Exactly Once

Amazon logoAmazon● EasyINTERNNEW GRADONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: Two reports describe finding or exposing users who logged in exactly once; the newer report specifically asks for the first such user. Neither gives a signature, so this contract treats the input as chronological login events and matches the central objective at about 90%.

The array userIds records successful login events in chronological order. A user may appear more than once.

Return the ID of the earliest user in the event stream whose total number of logins is exactly one. If every user logged in more than once, return the empty string.

"Earliest" refers to the position of the user's only event in userIds, not lexicographic order.

Sibling variants: same core, different skin

These four problems are sibling variants of the same first-unique pattern. Their story wrappers and query timing differ, while the core rule keeps the earliest value whose frequency is exactly one.

  1. Longest-Waiting Unique Task
  2. Dynamic Longest-Waiting Unique Task Queries
  3. First User to Log In Exactly Once (current)
  4. First Unique Character in a Stream

Function

firstSingleLogin(userIds: String[]) → String

Examples

Example 1

userIds = ["alice","bob","alice","carol"]return = "bob"

Alice appears twice. Bob and Carol each appear once, and Bob's event comes first.

Example 2

userIds = ["a","a","b","b"]return = ""

Every user appears more than once, so the answer is empty.

Example 3

userIds = ["zoe"]return = "zoe"

The only user logged in exactly once.

Constraints

  • 1 <= userIds.length <= 100000.
  • Each user ID is a nonempty alphanumeric string of length at most 40.
  • Events appear in chronological order.

More Amazon problems

  • Count Adjacent Symbol Pairs for BPEONSITE INTERVIEW · Seen Nov 2026
  • Count Adjacent Symbol Pairs for BPEONSITE INTERVIEW · Seen Nov 2026
  • First Non-Repeating CharacterOA · ONSITE INTERVIEW · Seen Nov 2026
See Amazon hiring insights
Saved
public String firstSingleLogin(String[] userIds) {
  // write your code here
}
Checking account…