2432. The Employee That Worked on the Longest Task Easy

@problem@discussion
#Array



1/**
2 * [2432] The Employee That Worked on the Longest Task
3 *
4 * There are n employees, each with a unique id from 0 to n - 1.
5 * You are given a 2D integer array logs where logs[i] = [idi, leaveTimei] where:
6 * 
7 * 	idi is the id of the employee that worked on the i^th task, and
8 * 	leaveTimei is the time at which the employee finished the i^th task. All the values leaveTimei are unique.
9 * 
10 * Note that the i^th task starts the moment right after the (i - 1)^th task ends, and the 0^th task starts at time 0.
11 * 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.
12 *  
13 * <strong class="example">Example 1:
14 * 
15 * Input: n = 10, logs = [[0,3],[2,5],[0,9],[1,15]]
16 * Output: 1
17 * Explanation: 
18 * Task 0 started at 0 and ended at 3 with 3 units of times.
19 * Task 1 started at 3 and ended at 5 with 2 units of times.
20 * Task 2 started at 5 and ended at 9 with 4 units of times.
21 * Task 3 started at 9 and ended at 15 with 6 units of times.
22 * 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.
23 * 
24 * <strong class="example">Example 2:
25 * 
26 * Input: n = 26, logs = [[1,1],[3,7],[2,12],[7,17]]
27 * Output: 3
28 * Explanation: 
29 * Task 0 started at 0 and ended at 1 with 1 unit of times.
30 * Task 1 started at 1 and ended at 7 with 6 units of times.
31 * Task 2 started at 7 and ended at 12 with 5 units of times.
32 * Task 3 started at 12 and ended at 17 with 5 units of times.
33 * The tasks with the longest time is task 1. The employees that worked on it is 3, so we return 3.
34 * 
35 * <strong class="example">Example 3:
36 * 
37 * Input: n = 2, logs = [[0,10],[1,20]]
38 * Output: 0
39 * Explanation: 
40 * Task 0 started at 0 and ended at 10 with 10 units of times.
41 * Task 1 started at 10 and ended at 20 with 10 units of times.
42 * 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.
43 * 
44 *  
45 * Constraints:
46 * 
47 * 	2 <= n <= 500
48 * 	1 <= logs.length <= 500
49 * 	logs[i].length == 2
50 * 	0 <= idi <= n - 1
51 * 	1 <= leaveTimei <= 500
52 * 	idi != idi+1
53 * 	leaveTimei are sorted in a strictly increasing order.
54 * 
55 */
56pub struct Solution {}
57
58// problem: https://leetcode.com/problems/the-employee-that-worked-on-the-longest-task/
59// discuss: https://leetcode.com/problems/the-employee-that-worked-on-the-longest-task/discuss/?currentPage=1&orderBy=most_votes&query=
60
61// submission codes start here
62
63impl Solution {
64    pub fn hardest_worker(n: i32, logs: Vec<Vec<i32>>) -> i32 {
65        0
66    }
67}
68
69// submission codes end
70
71#[cfg(test)]
72mod tests {
73    use super::*;
74
75    #[test]
76    fn test_2432() {
77    }
78}
79


Back
© 2025 bowen.ge All Rights Reserved.