High-Access Employees - Problem
Imagine you're a security officer monitoring employee badge access to a restricted facility. Your job is to identify employees who might be exhibiting suspicious behavior by accessing the system too frequently within short time periods.
You are given a 2D array access_times containing employee access records for a single day. Each record contains:
access_times[i][0]- Employee name (string)access_times[i][1]- Access time in 24-hour format (string like "0815" or "1430")
An employee is considered "high-access" if they accessed the system three or more times within any one-hour period.
Important Rules:
- Times exactly one hour apart are NOT in the same period (e.g., "0815" and "0915")
- Cross-day periods don't count (e.g., "2350" and "0010" are separate)
- You need to find any one-hour window with 3+ accesses
Goal: Return a list of all high-access employee names in any order.
Input & Output
example_1.py โ Basic High Access
$
Input:
access_times = [["a","0549"],["b","0457"],["a","0532"],["a","0621"],["b","0540"]]
โบ
Output:
["a"]
๐ก Note:
Employee 'a' has access times [0549, 0532, 0621]. After sorting: [0532, 0549, 0621]. The window [0532, 0549, 0621] spans 89 minutes, but we can find a valid window [0532, 0549] within 17 minutes. However, checking more carefully: from 0532 to 0549 is 17 minutes (valid), but we need 3 accesses in one window. Actually, let me recalculate: 0621-0532=89 minutes > 60, so we need to check smaller windows. The key insight is that times 0532, 0549 are within 60 minutes, and if there was a third access between 0532-0632, employee 'a' would be high-access.
example_2.py โ Multiple Employees
$
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': times [0808, 0829, 0809] โ sorted [0808, 0809, 0829]. Window from 0808 to 0829 is 21 minutes with 3 accesses โ HIGH ACCESS. Employee 'd': times [0002, 1508, 1444, 1410] โ sorted [0002, 1410, 1444, 1508]. Window from 1410 to 1508 is 58 minutes with 3 accesses โ HIGH ACCESS.
example_3.py โ No High Access
$
Input:
access_times = [["alice","0800"],["alice","0900"],["alice","1000"],["bob","0830"]]
โบ
Output:
[]
๐ก Note:
Alice has times [0800, 0900, 1000]. Each consecutive pair is exactly 60 minutes apart (0900-0800=100, 1000-0900=100), but we need times to be LESS than 60 minutes apart to be in the same window. Bob has only 1 access. No employee qualifies as high-access.
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 "HHMM"
- All access times are within the same day
Visualization
Tap to expand
Understanding the Visualization
1
Collect Access Data
Security system logs every badge scan with employee name and timestamp
2
Group by Employee
Sort all access records into employee-specific files
3
Time-Based Analysis
For each employee, sort their access times chronologically
4
Sliding Window Check
Use a one-hour sliding window to detect 3+ accesses in any period
5
Flag Suspicious Activity
Employees with high-frequency access patterns are flagged for review
Key Takeaway
๐ฏ Key Insight: Group access times by employee, sort chronologically, then use a sliding window to efficiently detect any one-hour period with 3+ accesses - like a smart security system automatically flagging suspicious access patterns!
๐ก
Explanation
AI Ready
๐ก Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code