← 返回 xai 的题目列表Calculate Active Hours for Twitter Spaces
类型:online_judge
Given the following records (operation, twitter_space, user, timestamp), return the total active hours of each Twitter space.
Input:
["create", "abc", "user_1", "1234567000"]
["join", "abc", "user_2", "1234567100"]
["leave", "abc", "user_2", "1234567300"]
["create", "def", "user_2", "1234568000"]
["leave", "def", "user_2", "1234568500"]
["leave", "abc", "user_1", "1234569000"]
Output:
{"abc": 2200, "def": 500}
Explanation: user1 stayed in 'abc' for a total of 2000, user2 stayed in 'abc' for a total of 200, user2 stayed in 'def' for a total of 500.
Follow-up: Generate top-k spaces with the largest number of users in real-time.
Example
Input
["create", "abc", "user_1", "1234567000"]
["join", "abc", "user_2", "1234567100"]
["leave", "abc", "user_2", "1234567300"]
["create", "def", "user_2", "1234568000"]
["leave", "def", "user_2", "1234568500"]
["leave", "abc", "user_1", "1234569000"]
Output
{"abc": 2200, "def": 500}