You are given n log lines. Each line begins with a timestamp in 24-hour HH:MM:SS format (exactly 8 characters), optionally followed by a single space and a free-form message (the message may be empty, any characters, or absent entirely). Seconds are ignored for bucketing purposes: convert each timestamp to minutes-since-midnight (HH*60+MM) and assign it to the bucket floor(minutes / B), where B is a bucket size in minutes given on the first line. B is guaranteed to evenly divide 1440 (the number of minutes in a day).
For every bucket that has at least one log line (only buckets that actually occur — not every possible bucket of the day), print one line: HH:MM-HH:MM: count, where the range is the bucket's [start, start+B) window formatted as 24-hour HH:MM, and count is the number of log lines that fall in it. A bucket whose window ends exactly at midnight is written with an end time of 24:00 (not 00:00). Print the buckets in ascending order of their start time.
Line 1: two integers n and B, space-separated.
Lines 2..n+1: each a log line starting with HH:MM:SS.
One line per non-empty bucket, ascending, formatted as described above.
B evenly divides 1440, 1 ≤ B ≤ 1440Example 1
Input
3 30 00:05:10 boot 00:20:00 ready 01:10:00 login
Expected
00:00-00:30: 2 01:00-01:30: 1
Explanation
With 30-minute buckets, the first two lines (minutes 5 and 20) fall in [0,30) -> `00:00-00:30: 2`; the third (minute 70) falls in [60,90) -> `01:00-01:30: 1`.
Example 2
Input
2 60 09:15:00 a 09:59:59 b
Expected
09:00-10:00: 2
Explanation
Both timestamps are within the same 60-minute hour bucket [540,600) -> `09:00-10:00: 2`.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →