Track Customer Visits and First-Time Visitors
Millions of customers visit our website every day. For each customer, we have a unique identifier that stays the same every time they visit. We have 2 kinds of customers: Recurrent Visitors, who have visited more than once, and One-Time Visitors, who have visited the website only once so far.
We want to implement a service that has 2 functionalities:
postCustomerVisitgetFirstOneTimeVisitor
这道题要求设计一个客户访问追踪服务,核心是同时维护“访问次数统计”和“当前仍只访问过一次的用户顺序”。通常可以用哈希表记录每个 customer 的访问次数,再配合队列或双向结构保存候选的一次性访客;当某个用户再次访问时,将其从一次性集合中失效。查询时返回最早仍满足“只访问一次”的用户。题目重点考察哈希表、队列 / 链表以及增量更新思路,适合面试中讨论时间复杂度与数据结构设计。