High-Access Employees - Problem

You are given a 2D array of strings access_times of size n. For each i where 0 ≤ i ≤ n - 1, access_times[i][0] represents the name of an employee, and access_times[i][1] represents the access time of that employee in 24-hour format ("0800" or "2250").

An employee is high-access if they accessed the system three or more times within a one-hour period. Times with exactly one hour of difference are not part of the same one-hour period. For example, "0815" and "0915" are not part of the same one-hour period.

Return a list containing the names of high-access employees in any order.

Input & Output

Example 1 — Multiple Employees
$ Input: access_times = [["a","0549"],["b","0457"],["a","0532"],["a","0621"],["b","0540"]]
Output: []
💡 Note: Employee 'a' has access times at 0549 (9:49), 0532 (5:32), and 0621 (6:21). After sorting: 532, 549, 621. The span from 532 to 621 is 89 minutes, which is greater than 60 minutes, so 'a' is not high-access. Employee 'b' only has 2 accesses. Therefore, no employees are high-access.
Example 2 — Close Time Window
$ Input: access_times = [["d","0002"],["c","0808"],["c","0829"],["e","0215"],["d","1508"],["d","1444"],["d","1410"],["c","0809"]]
Output: ["c","d"]
💡 Note: Employee 'c' has times 808, 829, 809. Sorted: 808, 809, 829. Window 808-829 = 21 minutes with 3 accesses. Employee 'd' has times 0002, 1508, 1444, 1410. Sorted: 2, 1410, 1444, 1508. Window 1410-1508 = 58 minutes with 3 accesses.
Example 3 — No Violations
$ Input: access_times = [["cd","0000"],["cd","0200"],["cd","0400"]]
Output: []
💡 Note: Employee 'cd' has times 0000, 0200, 0400. These are spaced 120 minutes apart (0000 to 0200 = 120 min, 0200 to 0400 = 120 min), so no 3 accesses occur within 60 minutes.

Constraints

  • 1 ≤ access_times.length ≤ 100
  • access_times[i].length == 2
  • 1 ≤ access_times[i][0].length ≤ 10
  • access_times[i][0] consists only of English small letters
  • access_times[i][1].length == 4
  • access_times[i][1] is in 24-hour time format

Visualization

Tap to expand
High-Access Employees INPUT access_times array: ["a", "0549"] ["b", "0457"] ["a", "0532"] ["a", "0621"] ["b", "0540"] Grouped by Employee: Employee "a" 3 accesses Employee "b" 2 accesses n = 5 access records 2 unique employees ALGORITHM STEPS 1 Group by Employee Create hashmap of times 2 Sort Times Sort each employee's times 3 Sliding Window Check 3+ times in 1hr 4 Mark High-Access Add to result list Employee "a" - Sorted: 0532 0549 0621 Window: 49 min (under 60) 3 accesses - HIGH ACCESS! "b": [0457, 0540] - only 2 times Not high-access FINAL RESULT High-Access Employees Found: ["a"] Why "a" is high-access: - 3 accesses within 1 hour - Times: 0532, 0549, 0621 - Span: 49 minutes (< 60) - Meets criteria: 3+ in 1hr Why "b" is NOT high-access: - Only 2 accesses total - Need 3+ for high-access Key Insight: Sort times per employee, then use sliding window of size 3. If time[i+2] - time[i] < 60 minutes, that employee is high-access. Note: exactly 60 min difference (e.g., 0815 to 0915) does NOT count as same period. Time complexity: O(n log n) due to sorting. Space: O(n) for grouping. TutorialsPoint - High-Access Employees | Sort and Sliding Window Approach
Asked in
Amazon 15 Microsoft 8
12.5K Views
Medium Frequency
~25 min Avg. Time
234 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen