Tap here to switch tabs
Problem
Submissions

Problem: The Employee That Worked on the Longest Task

med
30 min
Try to solve the The Employee That Worked on the Longest Task problem.

Statement

There are n employees, each assigned a unique identifier from 00 to n −1- 1.

You are given a 22D integer array logs where each element logs[i] = [idi_i, leaveTimei_i] indicates that the employee with identifier idi_i worked on the iextthi^{ ext{th}} task and finished it at time leaveTimei_i.

The 0extth0^{ ext{th}} task starts at time 00, and every subsequent task ii begins immediately when the previous task i−1i - 1 ends at leaveTimei−1_{i-1}. The duration of each task is the total time spent working on it.

Return the identifier of the employee who worked on the task with the longest duration. If there is a tie, return the smallest employee identifier among them.

Constraints:

  • 2≤2 \leq n ≤500\leq 500

  • 1≤1 \leq logs.length ≤500\leq 500

  • logs[i].length =2= 2

  • 0≤0 \leq idi≤_i \leq n −1- 1

  • 1≤1 \leq leaveTimei≤500_i \leq 500

  • idi≠_i \neq idi+1_{i+1}

  • leaveTimei_i values are sorted in strictly increasing order.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: The Employee That Worked on the Longest Task

med
30 min
Try to solve the The Employee That Worked on the Longest Task problem.

Statement

There are n employees, each assigned a unique identifier from 00 to n −1- 1.

You are given a 22D integer array logs where each element logs[i] = [idi_i, leaveTimei_i] indicates that the employee with identifier idi_i worked on the iextthi^{ ext{th}} task and finished it at time leaveTimei_i.

The 0extth0^{ ext{th}} task starts at time 00, and every subsequent task ii begins immediately when the previous task i−1i - 1 ends at leaveTimei−1_{i-1}. The duration of each task is the total time spent working on it.

Return the identifier of the employee who worked on the task with the longest duration. If there is a tie, return the smallest employee identifier among them.

Constraints:

  • 2≤2 \leq n ≤500\leq 500

  • 1≤1 \leq logs.length ≤500\leq 500

  • logs[i].length =2= 2

  • 0≤0 \leq idi≤_i \leq n −1- 1

  • 1≤1 \leq leaveTimei≤500_i \leq 500

  • idi≠_i \neq idi+1_{i+1}

  • leaveTimei_i values are sorted in strictly increasing order.