Chat Activity Counter
Asked at OpenAI
Reported by the problem's creator, not verified
Chat events arrive as a stream, and ChatTracker answers questions about recent activity. A chat is identified by the pair (user_id, chat_id): the same chat_id under two users is two different chats. Time is a whole number of minutes.
Memory must not grow with the length of the event history or with the number of chats ever seen; it follows the events that can still count.
Examples
Example 1
Input: init =
[], operations =[["process_event",[1,10,0]],["process_event",[1,10,5]],["process_event",[1,10,14]],["get_recent_message",[1,10]],["process_event",[2,20,15]],["get_recent_message",[1,10]],["get_recent_message",[2,20]],["get_recent_message",[1,20]],["get_recent_message",[3,30]]]Output:
[null,null,null,3,null,2,1,0,0]Explanation: The messages at 0, 5 and 14 are all within 14 minutes of the latest time 14, so the count is 3. The event at 15 for another chat moves the latest time to 15, which drops the message at 0 (15 minutes old) and leaves 2. Chat 20 of user 2 has 1, and chats that never appeared return 0.