2933. High-Access Employees
Asked at Atlassian
Difficulty
Medium
Time
O(n log n)
Space
O(n)
Pattern
Array
Companies
1
Problem
You get a list of access records. Each record is a pair: an employee name and a time written as four digits in 24-hour format, like "0800" or "2250". All records happen on the same day.
An employee is called high-access if they opened the system 3 or more times inside one hour. In other words, some group of 3 of their accesses must all fit inside a window of 60 minutes or less.
Two details change the answer. First, a gap of exactly 60 minutes does not count as the same hour. So "0815" and "0915" are in different windows, but "0815" and "0914" are in the same one. Second, the day does not wrap around: "2350" and "0005" are never in the same window, even though they are only 15 minutes apart on a clock.
Return the names of all high-access employees. The order does not matter.
Three accesses inside one hour
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 - ●
access_times[i][1] consists only of '0' to '9'
Examples
access_times = [["a","0549"],["b","0457"],["a","0532"],["a","0621"],["b","0540"]]["a"]access_times = [["d","0002"],["c","0808"],["c","0829"],["e","0215"],["d","1508"],["d","1444"],["d","1410"],["c","0809"]]["c","d"]access_times = [["cd","1025"],["ab","1025"],["cd","1046"],["cd","1055"],["ab","1124"],["ab","1120"]]["ab","cd"]Asked At
1 companies| Company | Difficulty | |
|---|---|---|
| Atlassian | Medium | View all Atlassian questions → |
How to Think About It
Group access times by username using a hash map
For each user, sort their access times and convert to numeric minutes
Use a sliding window to check if any 3 consecutive accesses fall within 60 minutes
For each pair of times separated by 2 positions, check if time[i+2] - time[i] <= 60
Collect all qualifying usernames and sort them for the final answer
Optimal Approach
Group all access times by username using a hash map. For each user, convert their time strings to numeric minutes and sort them. Use a sliding window of size 3: for each index i, check if times[i+2] - times[i] <= 60. If yes, this user accessed the system 3 times within a 60-minute window, so mark them as high-access. Collect all qualifying usernames and sort them alphabetically. The grouping step takes O(n) time, sorting each user times takes O(m log m) where m is per-user accesses, and the sliding window scan is O(m) per user. Overall complexity is O(n log n) dominated by sorting.
Sort, then slide a window of 3
What Trips People Up in Real Interviews
Convert "HHMM" string to integer minutes: int(time[:2]) * 60 + int(time[2:])
Clarify that the window is strictly less than 60 minutes or within 60 minutes
After grouping by user, the key insight is checking every 3rd element gap
Sorting users at the end is required for the output format
Edge case: user with exactly 2 accesses can never be high-access
Solution Code
O(n log n) timedef findHighAccessEmployees(access_times):
from collections import defaultdict
user_times = defaultdict(list)
for name, time in access_times:
user_times[name].append(int(time[:2]) * 60 + int(time[2:]))
res = []
for name, times in user_times.items():
times.sort()
for i in range(len(times) - 2):
if times[i + 2] - times[i] <= 60:
res.append(name)
break
res.sort()
return resFrequently Asked Questions
What is the High-Access Employees problem?
You are given an array of access times where each element is a string in the format "HHMM" representing a 24-hour time. A user is considered a high-access employee if they access the system at least 3 times within any 1-hour (60 minute) window. Return the sorted list of usernames who are high-access employees. This problem tests sliding window and time-based pattern detection.
How do you solve High-Access Employees?
The optimal approach runs in O(n log n) time and O(n) space. Scroll up to "Optimal Approach" for the step-by-step walkthrough, diagrams, and code in Python, C++ and Java.
What companies ask High-Access Employees?
High-Access Employees is asked at Atlassian. It is a medium difficulty problem.
What are common mistakes on High-Access Employees?
- Convert "HHMM" string to integer minutes: int(time[:2]) * 60 + int(time[2:])
- Clarify that the window is strictly less than 60 minutes or within 60 minutes
- After grouping by user, the key insight is checking every 3rd element gap
- Sorting users at the end is required for the output format
- Edge case: user with exactly 2 accesses can never be high-access