Design a class WebsiteTracker that processes a stream of customer visits to a site. The class must implement two methods:
visit(int customerId): Invoked each time the customer with identifier customerId lands on the website.firstUnique(): Returns the customerId of the first unique visitor (the one whose earliest appearance is the smallest among all customers that have visited exactly once so far). If there is no customer with a single visit, return -1.All customer IDs are positive integers, and you may assume they are valid. The tracker should handle a large number of calls efficiently.
Example 1:
Input:
visit(5)
visit(7)
visit(5)
visit(8)
firstUnique()
Output: 7
Explanation: Visits: 5, 7, 5, 8. Customer 5 visited twice and is no longer unique. Customers 7 and 8 each visited once. Among them, 7 appeared first, so firstUnique() returns 7.
operations = ["visit 5", "visit 7", "visit 5", "visit 8", "firstUnique"]7
empty
We start with an empty tracker. No customers have visited yet.
Example 2:
Input:
visit(1), visit(2), visit(3), firstUnique()
visit(2), firstUnique()
visit(1), firstUnique()
Output:
firstUnique() returns 1 on the first call, 1 on the second call, and 3 on the third call.
Explanation: At first, every customer has exactly one visit; 1 is the earliest unique. After 2 visits a second time, 2 is removed from the unique set, but 1 remains unique and is still earliest. After 1's second visit, only 3 remains unique, so it becomes the first unique.
Example 3:
Input:
visit(10), visit(10), firstUnique()
Output: -1
Explanation: Customer 10 visited twice; there are no unique visitors.
Constraints:
1 <= customerId <= 10^9visit and firstUnique will not exceed 10^5.operations = ["visit 5", "visit 7", "visit 5", "visit 8", "firstUnique"]7
empty
We start with an empty tracker. No customers have visited yet.