**The Employee That Worked on the Longest Task solution leetcode** – There are `n`

employees, each with a unique id from `0`

to `n - 1`

.

Table of Contents

## [Solution] The Employee That Worked on the Longest Task solution leetcode

You are given a 2D integer array `logs`

where `logs[i] = [id`

where:_{i}, leaveTime_{i}]

`id`

is the id of the employee that worked on the_{i}`i`

task, and^{th}`leaveTime`

is the time at which the employee finished the_{i}`i`

task. All the values^{th}`leaveTime`

are_{i}**unique**.

Note that the `i`

task starts the moment right after the ^{th}`(i - 1)`

task ends, and the ^{th}`0`

task starts at time ^{th}`0`

.

Return *the id of the employee that worked the task with the longest time.* If there is a tie between two or more employees, return* the smallest id among them*.

## [Solution] The Employee That Worked on the Longest Task solution leetcode

Input:n = 10, logs = [[0,3],[2,5],[0,9],[1,15]]Output:1Explanation:Task 0 started at 0 and ended at 3 with 3 units of times. Task 1 started at 3 and ended at 5 with 2 units of times. Task 2 started at 5 and ended at 9 with 4 units of times. Task 3 started at 9 and ended at 15 with 6 units of times. The task with the longest time is task 3 and the employee with id 1 is the one that worked on it, so we return 1.

## [Solution] The Employee That Worked on the Longest Task solution leetcode

Input:n = 26, logs = [[1,1],[3,7],[2,12],[7,17]]Output:3Explanation:Task 0 started at 0 and ended at 1 with 1 unit of times. Task 1 started at 1 and ended at 7 with 6 units of times. Task 2 started at 7 and ended at 12 with 5 units of times. Task 3 started at 12 and ended at 17 with 5 units of times. The tasks with the longest time is task 1. The employees that worked on it is 3, so we return 3.

## [Solution] The Employee That Worked on the Longest Task solution leetcode

Input:n = 2, logs = [[0,10],[1,20]]Output:0Explanation:Task 0 started at 0 and ended at 10 with 10 units of times. Task 1 started at 10 and ended at 20 with 10 units of times. The tasks with the longest time are tasks 0 and 1. The employees that worked on them are 0 and 1, so we return the smallest id 0.

## [Solution] The Employee That Worked on the Longest Task solution leetcode

`2 <= n <= 500`

`1 <= logs.length <= 500`

`logs[i].length == 2`

`0 <= id`

_{i}<= n - 1`1 <= leaveTime`

_{i}<= 500`id`

_{i}!= id_{i+1}`leaveTime`

are sorted in a strictly increasing order._{i}