Design a customer visit tracking service for a website that receives millions of visits every day. Each customer has a unique identifier that remains the same across all their visits.
A customer is a one-time visitor if they have visited exactly once so far. A customer is a recurrent visitor if they have visited more than once.
The service should record customer visits, return a customer's latest login timestamp, and return the first customer who is still a one-time visitor.
currentTimestamp.postCustomerVisit will have monotonically non-decreasing currentTimestamp values.-1.CustomerVisitTracker()
void postCustomerVisit(String customerId, int currentTimestamp)
customerId at currentTimestamp.int getLastLoginTimestamp(String customerId)
customerId.-1 if customerId has never visited.String getFirstOneTimeVisitor()
1 ≤ customerId.length() ≤ 100customerId contains only lowercase English letters, uppercase English letters, and digits.0 ≤ currentTimestamp ≤ 1,000,000,0001,000,000.CustomerVisitTracker tracker = new CustomerVisitTracker()
tracker.postCustomerVisit(customerId = "alice", currentTimestamp = 10)
tracker.postCustomerVisit(customerId = "bob", currentTimestamp = 15)
tracker.getFirstOneTimeVisitor()
Output: "alice"
Explanation: Both customers have exactly one visit, but "alice" became a one-time visitor earlier.
CustomerVisitTracker tracker = new CustomerVisitTracker()
tracker.postCustomerVisit(customerId = "john", currentTimestamp = 20)
tracker.postCustomerVisit(customerId = "mike", currentTimestamp = 25)
tracker.postCustomerVisit(customerId = "john", currentTimestamp = 30)
tracker.getFirstOneTimeVisitor()
Output: "mike"
Explanation: "john" has visited twice, so only "mike" is still a one-time visitor.
CustomerVisitTracker tracker = new CustomerVisitTracker()
tracker.postCustomerVisit(customerId = "cust2", currentTimestamp = 100)
tracker.postCustomerVisit(customerId = "cust1", currentTimestamp = 100)
tracker.getFirstOneTimeVisitor()
Output: "cust1"
Explanation: Both customers have the same first visit timestamp, so the lexicographically smaller customer identifier is returned.
CustomerVisitTracker tracker = new CustomerVisitTracker()
tracker.postCustomerVisit(customerId = "tom", currentTimestamp = 5)
tracker.getLastLoginTimestamp(customerId = "tom")
Output: 5
tracker.postCustomerVisit(customerId = "tom", currentTimestamp = 50)
tracker.getLastLoginTimestamp(customerId = "tom")
Output: 50
Explanation: The latest login timestamp for "tom" is updated after each visit.
CustomerVisitTracker tracker = new CustomerVisitTracker()
tracker.postCustomerVisit(customerId = "a1", currentTimestamp = 7)
tracker.postCustomerVisit(customerId = "a1", currentTimestamp = 9)
tracker.getFirstOneTimeVisitor()
Output: ""
Explanation: The only customer is recurrent, so there is no one-time visitor.