EasyNo. 2432
The Employee That Worked on the Longest Task — LeetCode 2432 Python Solution
- Topics
- Array
- Reading time
- 2 min
- Source
- leetcode.com
The problem
There are n employees, each with a unique id from 0 to n - 1. You are given a 2D integer array logs where logs[i] = [idi, leaveTimei] where: idi is the id of the employee that worked on the ith task, and leaveTimei is the time at which the employee finished the ith task.
Example
- Input
- n = 10, logs = [[0,3],[2,5],[0,9],[1,15]]
- Output
- 1
- Explanation
- Task 0 started at 0 and ended at 3 with 3 units of times.
Python solution
class Solution:
def hardestWorker(self, n: int, logs: List[List[int]]) -> int:
last = mx = ans = 0
for uid, t in logs:
t -= last
if mx < t or (mx == t and ans > uid):
ans, mx = uid, t
last += t
return ansComplexity
- Time
- O(n)where n is the length of the array logs
- Space · auxiliary
- O(1)
Related problems
| No. | Problem | Difficulty |
|---|---|---|
| 0057 | Insert Interval | Medium |
| 0228 | Summary Ranges | Easy |
| 0485 | Max Consecutive Ones | Easy |
| 0665 | Non-decreasing Array | Medium |
| 0674 | Longest Continuous Increasing Subsequence | Easy |
| 0699 | Falling Squares | Hard |
Frequently asked questions
- How hard is LeetCode 2432. The Employee That Worked on the Longest Task?
LeetCode 2432. The Employee That Worked on the Longest Task is rated Easy on LeetCode.
- What is the time complexity of LeetCode 2432. The Employee That Worked on the Longest Task?
The Python solution on this page runs in O(n), where n is the length of the array logs.
- What is the space complexity of LeetCode 2432. The Employee That Worked on the Longest Task?
The Python solution on this page uses O(1) auxiliary space.
- What topics does LeetCode 2432. The Employee That Worked on the Longest Task cover?
LeetCode 2432. The Employee That Worked on the Longest Task is tagged Array on LeetCode.