← 返回 microsoft 的题目列表Get Most Active Users Within Time Range
类型:online_judge
Implement a function GetMostActiveUsers that takes a list of events and three integers startTime, endTime, k. Each event consists of a user ID, a timestamp, and a boolean isOnline. The events are unordered. Return the top k most active users between startTime and endTime, sorted by active time in descending order.
Input Format
events: A list where each element is a tuple (string userId, int timestamp, bool isOnline)
startTime: An integer indicating the beginning of the time period
endTime: An integer indicating the end of the time period
k: An integer for the number of top users to return
Output Format
A list of the IDs of the top k most active users
Sample Input
[
("A", 1, true),
("A", 4, false),
("B", 2, true),
("B", 6, false),
("C", 3, true),
("C", 5, false)
]
startTime = 1
endTime = 6
k = 2
Expected Output
["B", "A"]
Explanation
User A is online from 1 to 4, active time is 3 units.
User B is online from 2 to 6, active time is 4 units.
User C is online from 3 to 5, active time is 2 units.
B is the most active, followed by A.
Example
Input
[['A', 1, True], ['A', 4, False], ['B', 2, True], ['B', 6, False], ['C', 3, True], ['C', 5, False]], 1, 6, 2