Problem · Array
First User to Log In Exactly Once
Learn this problemProblem statement
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.
Function
firstSingleLogin(userIds: String[]) → StringExamples
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.