Earliest One-Hour Badge Alert Times
Problem statement
Each row of records is [employee,time] and records an employee badging into a secured room. The rows are unordered. Each time is a valid 24-hour compact HHMM string of one to four digits, such as 800 or 2250. All events occur during a single day.
Find every employee with at least three badge events in an inclusive one-hour period. If several such periods exist, select the earliest one for that employee. Return every badge time in that selected hour, rather than only the first three.
For this exercise, assume each candidate hour starts at one of the employee's badge events and spans the next 60 minutes, including both endpoints. An hour does not wrap across midnight.
For this exercise, assume compact times are left-padded to four digits when interpreted, so 5 means 00:05 and 109 means 01:09. Leading zeroes are allowed.
Return one row [employee,time1,time2,...] per qualifying employee. For this exercise, assume employee rows are sorted lexicographically; times are sorted chronologically while retaining their original text, and equal times preserve input order. Each record counts separately, even when the employee and time are repeated. An empty input returns an empty result.
Function
badgeAlerts(records: String[][]) → String[][]Examples
Example 1
records = [["Paul","1355"],["Jennifer","1910"],["John","835"],["John","830"],["Paul","1315"],["John","1615"],["John","1640"],["Paul","1405"],["John","855"],["John","930"],["John","915"],["John","730"],["John","940"],["Jennifer","1335"],["Jennifer","730"],["John","1630"],["Jennifer","5"]]return = [["John","830","835","855","915","930"],["Paul","1315","1355","1405"]]The original report's earliest qualifying windows are retained, with employee rows sorted for this exercise. Every badge time within the selected hour is included.
Example 2
records = [["Amy","1000"],["Amy","1030"],["Amy","1100"],["Amy","1101"],["Bob","10"],["Bob","111"],["Bob","212"]]return = [["Amy","1000","1030","1100"]]Amy's hour begins at 10:00 and includes the access exactly 60 minutes later. The next access is outside that hour; Bob has no qualifying hour.
Constraints
- For this exercise, assume there are at most
1000events. - Employee identifiers are nonempty case-sensitive alphanumeric strings of at most
30characters. - Every time represents an hour from
0through23and a minute from0through59. - Each input row has exactly two strings.