Leetcode Problem 2432. The Employee That Worked on the Longest Task

2432. The Employee That Worked on the Longest Task

Leetcode Solutions

Find the Employee with the Longest Task Time

  1. Initialize max_duration to 0 and employee_id to the ID of the first employee in the logs.
  2. Iterate through the logs array starting from the second log entry.
  3. For each log entry, calculate the duration of the current task by subtracting the end time of the previous task from the current task's end time.
  4. If the current duration is greater than max_duration, update max_duration and employee_id with the current duration and employee ID, respectively.
  5. If the current duration is equal to max_duration, update employee_id only if the current employee ID is smaller than the current employee_id.
  6. After iterating through all log entries, return employee_id as the result.
UML Thumbnail

Use a Pair Array to Track Task Durations

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...