Log Analyzer:
Given logs with a service name and timestamp, find the service with the maximum number of requests in any rolling t-second window.
Assumptions:
Each log contains a timestamp in seconds and a service name.
The window is t seconds.
Return the service and its maximum request count.
If multiple services tie, return all tied services.
Example: t = 300
logs = [(10, "A"),
(40, "B"),
(100, "A"),
(200, "A"),
(260, "B"),
(280, "A"),
(310, "B"),
(210, "A")]
Output:
Services: ['A']
maximum requests: 5
Example: t = 60
logs = [(10, "A"),
(20, "B"),
(30, "A"),
(40, "B"),
(50, "A"),
(60, "B"),
(70, "A")]
Output:
Services: ['A']
maximum requests: 4
Example: t = 10
logs = [(100, "A"),
(100, "A"),
(100, "B"),
(100, "B"),
(110, "B"),
(110, "A")]
Output:
Services: ['A', 'B']
maximum requests: 3
Discussion
Loading comments…