Earliest One-Hour Badge Alert Times
Problem statement
The parallel arrays keyName and keyTime describe unordered badge events: entry i records employee keyName[i] badging in at keyTime[i]. Each time is a valid 24-hour string in HH:MM format. 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 every time has exactly five characters and uses two digits for the hour and minute.
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(keyName: String[], keyTime: String[]) → String[][]Examples
Example 1
keyName = ["daniel","daniel","daniel","daniel","daniel","daniel","luis","luis","luis","luis"]keyTime = ["10:00","10:40","10:50","10:51","10:55","11:00","09:00","11:00","13:00","15:00"]return = [["daniel","10:00","10:40","10:50","10:51","10:55","11:00"]]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
keyName = ["Amy","Amy","Amy","Amy","Bob","Bob","Bob"]keyTime = ["10:00","10:30","11:00","11:01","00:10","01:11","02:12"]return = [["Amy","10:00","10:30","11:00"]]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
2000events. - Employee identifiers are nonempty case-sensitive alphanumeric strings of at most
30characters. - Every time represents an hour from
0through23and a minute from0through59. keyName.length == keyTime.length.