/*
* @lc app=leetcode.cn id=2432 lang=typescript
*
* [2432] 处理用时最长的那个任务的员工
*/
// @lc code=start
function hardestWorker(n: number, logs: number[][]): number {}
// @lc code=end
function hardestWorker(n: number, logs: number[][]): number {
let pre = 0,
res = Infinity,
max = -Infinity
for (let [id, t] of logs) {
const d = t - pre
if (d > max) {
max = d
res = id
} else if (d === max && id < res) {
res = id
}
pre = t
}
return res
}
test.each([
{
input: {
n: 10,
logs: [
[0, 3],
[2, 5],
[0, 9],
[1, 15],
],
},
output: 1,
},
{
input: {
n: 26,
logs: [
[1, 1],
[3, 7],
[2, 12],
[7, 17],
],
},
output: 3,
},
{
input: {
n: 2,
logs: [
[0, 10],
[1, 20],
],
},
output: 0,
},
])('input: n = $input.n, logs = $input.logs', ({ input: { n, logs }, output }) => {
expect(hardestWorker(n, logs)).toEqual(output)
})