Skip to main content

High-Access Employees - Solution & Explanation

MediumArrayHash TableStringSorting14 min readAsked at: Atlassian, Karat
Practice this problem

Problem Statement

You are given a 2D 0-indexed array of strings, access_times, with 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. All entries in access_times are within the same day.

The access time is represented as four digits using a 24-hour time format, for example, "0800" or "2250".

An employee is said to be high-access if he has accessed the system three or more times within a one-hour period.

Times with exactly one hour of difference are not considered part of the same one-hour period. For example, "0815" and "0915" are not part of the same one-hour period.

Access times at the start and end of the day are not counted within the same one-hour period. For example, "0005" and "2350" are not part of the same one-hour period.

Return a list that contains the names of high-access employees with any order you want.

 

Example 1:

Input: access_times = [["a","0549"],["b","0457"],["a","0532"],["a","0621"],["b","0540"]]
Output: ["a"]
Explanation: "a" has three access times in the one-hour period of [05:32, 06:31] which are 05:32, 05:49, and 06:21.
But "b" does not have more than two access times at all.
So the answer is ["a"].

Example 2:

Input: access_times = [["d","0002"],["c","0808"],["c","0829"],["e","0215"],["d","1508"],["d","1444"],["d","1410"],["c","0809"]]
Output: ["c","d"]
Explanation: "c" has three access times in the one-hour period of [08:08, 09:07] which are 08:08, 08:09, and 08:29.
"d" has also three access times in the one-hour period of [14:10, 15:09] which are 14:10, 14:44, and 15:08.
However, "e" has just one access time, so it can not be in the answer and the final answer is ["c","d"].

Example 3:

Input: access_times = [["cd","1025"],["ab","1025"],["cd","1046"],["cd","1055"],["ab","1124"],["ab","1120"]]
Output: ["ab","cd"]
Explanation: "ab" has three access times in the one-hour period of [10:25, 11:24] which are 10:25, 11:20, and 11:24.
"cd" has also three access times in the one-hour period of [10:25, 11:24] which are 10:25, 10:46, and 10:55.
So the answer is ["ab","cd"].

 

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'.

Approach Overview

Problem Overview: You receive a list of employee access logs where each record contains an employee name and a time in HHMM format. The goal is to return all employees who accessed the system three or more times within any one-hour window.

Approach 1: Sorting and Sliding Window (O(n log n) time, O(n) space)

The most practical solution groups logs by employee, converts the access time into minutes, and sorts each employee's access list. Sorting ensures chronological order so you can scan for any 60‑minute window containing at least three accesses. Use a sliding window (two pointers) over the sorted list: move the right pointer forward and check whether time[right] - time[left] <= 60. If the window size reaches three, mark that employee as high‑access. If the time gap exceeds 60 minutes, move the left pointer forward to shrink the window. Sorting dominates the cost, giving O(n log n) time overall and O(n) space for grouped logs.

This approach works well because access events for each employee are independent. Sorting plus a sliding window efficiently detects dense time intervals without repeatedly scanning the entire list. The technique appears frequently in interval and log analysis problems and combines ideas from sorting and the sliding window pattern.

Approach 2: Hash Map and Fixed Interval Counting (O(n log n) time, O(n) space)

Another clean approach uses a hash table mapping each employee to a list of their access times. After building the map, convert times to minutes and sort each employee's list. Instead of a dynamic sliding window, check fixed triplets: for every index i, verify whether times[i + 2] - times[i] <= 60. If true, the three accesses fall inside a one‑hour window, so the employee qualifies. Because only triplets are checked, the scan is linear after sorting.

This method reduces pointer management and keeps the logic simple. Sorting each employee's access list still determines the total time complexity. Space remains O(n) for storing grouped logs.

Recommended for interviews: The sorting + sliding window approach is the one most interviewers expect. It shows you recognize the chronological constraint and can efficiently maintain a dynamic time window. The hash‑map triplet check is slightly simpler and equally valid, but the sliding window demonstrates stronger familiarity with common log‑analysis patterns.

Approach 1: Sorting and Sliding Window Approach

This approach involves converting access times into minutes, then sorting these times for each employee. After sorting the times, a sliding window technique is used to determine if there are at least three access events within a one-hour period for any employee.

The solution first converts each access time into minutes from midnight to simplify time arithmetic. It then groups and sorts access times by employee. A sliding window iterates over each employee's sorted times to check whether three accesses fall within any 60-minute period, thereby identifying high-access employees.

Code

Python

Java

C#

Complexity

Time Complexity: O(N log N) due to sorting of times.
Space Complexity: O(N) for storing the access times by employee.

Try this approach in the editor →

Approach 2: Hash Map and Fixed Interval Counting

This approach directly counts the access times within any possible one-hour interval by mapping employees to a frequency of their access times in a hash map, then checking possible overlaps within an hour and maintaining a count.

This C++ solution uses a map to store access times of each employee as a multiset for automatic sorting. It counts accesses within a one-hour frame using two iterators (pointers) on these sorted times to find potential high-access events.

Code

C++

JavaScript

Complexity

Time Complexity: O(N log N) for insertion into multiset which maintains sorted order.
Space Complexity: O(N) due to storage of times in the multiset.

Try this approach in the editor →

Approach 3: Hash Table + Sorting

We use a hash table d to store all access times of each employee, where the key is the employee's name, and the value is an integer array, representing all access times of the employee, which are the number of minutes from the start of the day at 00:00.

For each employee, we sort all their access times in ascending order. Then we traverse all access times of the employee. If there are three consecutive access times t_1, t_2, t_3 that satisfy t_3 - t_1 < 60, then the employee is a high-frequency visitor, and we add their name to the answer array.

Finally, we return the answer array.

The time complexity is O(n times log n), and the space complexity is O(n). Here, n is the number of access records.

Code

Python

Java

C++

Go

TypeScript

Try this approach in the editor →

Complexity Comparison

ApproachComplexity
Sorting and Sliding Window Approach

Time Complexity: O(N log N) due to sorting of times.
Space Complexity: O(N) for storing the access times by employee.

Hash Map and Fixed Interval Counting

Time Complexity: O(N log N) for insertion into multiset which maintains sorted order.
Space Complexity: O(N) due to storage of times in the multiset.

Hash Table + Sorting—

Detailed Complexity Analysis

ApproachTimeSpaceWhen to Use
Sorting + Sliding WindowO(n log n)O(n)Best general solution for detecting time windows within sorted logs
Hash Map + Fixed Triplet CheckO(n log n)O(n)Simpler logic when only checking groups of three accesses

Video Solution

2933. High-Access Employees | Hashing | Weekly 371 • Tech Courses • 967 views views

Watch 5 more video solutions →

Frequently Asked Questions

Is High-Access Employees easy or hard?
High-Access Employees is considered a medium difficulty problem. The challenge lies in recognizing the one-hour window constraint and applying sorting with a sliding window or indexed comparison efficiently.
High-Access Employees Python/Java solution
Typical implementations use a dictionary or HashMap to group access times, convert the HHMM strings into minutes, sort the times, and scan for any three accesses within 60 minutes. The same logic works across Python, Java, C++, and C#.
How to solve High-Access Employees in O(n)?
Pure O(n) is difficult because the access logs are not guaranteed to be sorted by time. Sorting is usually required to evaluate time windows correctly. After sorting, the window check runs in linear time, making the total complexity O(n log n).
What is the best approach for High-Access Employees?
The sorting and sliding window approach is the most commonly used solution. Group logs by employee, sort each employee's access times, and use a two-pointer window to check if three accesses occur within 60 minutes. The total complexity is O(n log n) due to sorting.
Is High-Access Employees asked at Google/Amazon/Meta?
Log analysis and sliding window problems similar to High-Access Employees appear in interviews at companies like Amazon, Google, and Meta. They often test your ability to process time-based events efficiently using sorting and hash maps.
What data structure is used in High-Access Employees?
The main data structure is a hash map that groups access times by employee name. After grouping, arrays or lists store the times, which are sorted and scanned using a sliding window or triplet comparison.
What is the time complexity of High-Access Employees?
Most optimal solutions run in O(n log n) time. The cost comes from sorting access times for each employee before scanning for a one-hour window. The scanning step itself is linear.

Ready to solve this problem?

Practice High-Access Employees with our built-in code editor and test cases.

Practice on FleetCode