FastPrepEarliest One-Hour Badge Alert Times

Earliest One-Hour Badge Alert Times

Atlassian logoAtlassian● MediumFULLTIMEPHONE SCREEN
Learn

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"],["Jose","835"],["Jose","830"],["Paul","1315"],["Chloe","0"],["Chloe","1910"],["Jose","1615"],["Jose","1640"],["Paul","1405"],["Jose","855"],["Jose","930"],["Jose","915"],["Jose","730"],["Jose","940"],["Jennifer","1335"],["Jennifer","730"],["Jose","1630"],["Jennifer","5"],["Chloe","1909"],["Zhang","1"],["Zhang","10"],["Zhang","109"],["Zhang","110"],["Amos","1"],["Amos","2"],["Amos","400"],["Amos","500"],["Amos","503"],["Amos","504"],["Amos","601"],["Amos","602"],["Paul","1416"]]return = [["Amos","500","503","504"],["Jose","830","835","855","915","930"],["Paul","1315","1355","1405"],["Zhang","10","109","110"]]

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 1000 events.
  • Employee identifiers are nonempty case-sensitive alphanumeric strings of at most 30 characters.
  • Every time represents an hour from 0 through 23 and a minute from 0 through 59.
  • Each input row has exactly two strings.

More Atlassian problems

See Atlassian hiring insights
public String[][] badgeAlerts(String[][] records) {
    // Write your code here.
    return new String[0][0];
}
records[["Paul","1355"],["Jennifer","1910"],["Jose","835"],["Jose","830"],["Paul","1315"],["Chloe","0"],["Chloe","1910"],["Jose","1615"],["Jose","1640"],["Paul","1405"],["Jose","855"],["Jose","930"],["Jose","915"],["Jose","730"],["Jose","940"],["Jennifer","1335"],["Jennifer","730"],["Jose","1630"],["Jennifer","5"],["Chloe","1909"],["Zhang","1"],["Zhang","10"],["Zhang","109"],["Zhang","110"],["Amos","1"],["Amos","2"],["Amos","400"],["Amos","500"],["Amos","503"],["Amos","504"],["Amos","601"],["Amos","602"],["Paul","1416"]]
expected[["Amos", "500", "503", "504"], ["Jose", "830", "835", "855", "915", "930"], ["Paul", "1315", "1355", "1405"], ["Zhang", "10", "109", "110"]]
Checking account…