High-Access Employees — LeetCode 2933 Python Solution
- Problem
- #2933
- Pattern
- Sorting
- Reading time
- 2 min
- Source
- leetcode.com
The problem
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.
Example
- 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.
Python solution
class Solution:
def findHighAccessEmployees(self, access_times: List[List[str]]) -> List[str]:
d = defaultdict(list)
for name, t in access_times:
d[name].append(int(t[:2]) * 60 + int(t[2:]))
ans = []
for name, ts in d.items():
ts.sort()
if any(ts[i] - ts[i - 2] < 60 for i in range(2, len(ts))):
ans.append(name)
return ansComplexity
| Measure | Complexity |
|---|---|
| Time | O(n \times \log n) |
| Space | O(n) auxiliary |
Pattern: Sorting
Spend O(n log n) once to buy an ordering that makes the rest of the problem trivial. LeetCode 2933. High-Access Employees is filed here because LeetCode tags it Sorting, which is the vocabulary this hub collects.
The sorting guide has the Python template for the pattern and the 401 LeetCode problems that use it.
Related problems
Frequently asked questions
- How hard is LeetCode 2933. High-Access Employees?
- LeetCode 2933. High-Access Employees is rated Medium on LeetCode.
- What is the time complexity of LeetCode 2933. High-Access Employees?
- The Python solution on this page runs in O(n \times \log n).
- What is the space complexity of LeetCode 2933. High-Access Employees?
- The Python solution on this page uses O(n) auxiliary space.
- What topics does LeetCode 2933. High-Access Employees cover?
- LeetCode 2933. High-Access Employees is tagged Array, Hash Table, String and Sorting on LeetCode.