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
๐Ÿข Security Badge Monitoring SystemRaw Data[Alice,0830][Bob,0900][Alice,0845]Group byEmployeeAlice: [0830,0845]Bob: [0900]Sort TimesAlice: [0830,0845](already sorted)SlidingWindowCheck 1-hourwindowsSliding Window Analysis for AliceTimes: [0830, 0845, 0915, 0920]0830084509150920One-hour windowโœ“ Window [0845-0945] contains: 0845, 0915, 0920๐Ÿšจ 3 accesses found! Alice is HIGH ACCESS๐ŸŽฏ Result: Alice flagged for security review
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!
Asked in
Amazon 45 Google 32 Microsoft 28 Meta 25
24.5K Views
Medium Frequency
~18 min Avg. Time
890 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