2518. The Employee That Worked on the Longest Task
My accepted Python solution to LeetCode problem 2518, The Employee That Worked on the Longest Task, running in 5ms.
- Difficulty: Easy
- Python
- Runtime 5ms
- Memory 17.5MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 5ms, memory 17.5MB, accepted 2026-01-01.
class Solution:
def hardestWorker(self, n: int, logs: List[List[int]]) -> int:
max_time = logs[0][1]
result = logs[0][0]
prev_end = logs[0][1]
for i in range(1, len(logs)):
duration = logs[i][1] - prev_end
if duration > max_time or (duration == max_time and logs[i][0] < result):
max_time = duration
result = logs[i][0]
prev_end = logs[i][1]
return result