Leetcode 2933: High-Access Employees

grid47
grid47
Exploring patterns and algorithms
Jan 18, 2024 7 min read

You are given a 2D array, access_times, where each entry contains an employee’s name and their system access time in 24-hour format (HHMM). An employee is considered ‘high-access’ if they accessed the system at least three times within any one-hour window. The task is to identify all such high-access employees and return their names.
Problem
Approach
Steps
Complexity
Input: The input is a list of lists, where each sublist contains a string representing an employee's name and another string representing their access time.
Example: [['a', '0549'], ['b', '0457'], ['a', '0532'], ['a', '0621'], ['b', '0540']]
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 lowercase letters
• access_times[i][1].length == 4
• access_times[i][1] is in 'HHMM' 24-hour format
Output: Return a list of employee names who are considered high-access. The order of the names does not matter.
Example: ['a']
Constraints:
• The list should contain names of high-access employees only.
Goal: Identify employees who accessed the system at least three times within any one-hour window.
Steps:
• Convert the access times into minutes.
• Sort the times for each employee.
• Use a sweep-line approach to check if three or more accesses occur within any 60-minute period.
Goal: The constraints ensure that the solution efficiently handles a moderate-sized dataset (up to 100 entries).
Steps:
• The algorithm should handle up to 100 employee access records efficiently.
Assumptions:
• Each access time entry is guaranteed to be a valid four-digit time string in 24-hour format.
Input: [['a', '0549'], ['b', '0457'], ['a', '0532'], ['a', '0621'], ['b', '0540']]
Explanation: 'a' has three access times (05:32, 05:49, and 06:21) within the one-hour period from 05:32 to 06:31, making them a high-access employee. 'b' does not have three access times in any one-hour period, so they are not included in the result.

Link to LeetCode Lab


LeetCode Solutions Library / DSA Sheets / Course Catalog
comments powered by Disqus