3386. Button with Longest Push Time Easy
1/**
2 * [3386] Button with Longest Push Time
3 *
4 * You are given a 2D array events which represents a sequence of events where a child pushes a series of buttons on a keyboard.
5 * Each events[i] = [indexi, timei] indicates that the button at index indexi was pressed at time timei.
6 *
7 * The array is sorted in increasing order of time.
8 * The time taken to press a button is the difference in time between consecutive button presses. The time for the first button is simply the time at which it was pressed.
9 *
10 * Return the index of the button that took the longest time to push. If multiple buttons have the same longest time, return the button with the smallest index.
11 *
12 * <strong class="example">Example 1:
13 * <div class="example-block">
14 * Input: <span class="example-io">events = [[1,2],[2,5],[3,9],[1,15]]</span>
15 * Output: <span class="example-io">1</span>
16 * Explanation:
17 *
18 * Button with index 1 is pressed at time 2.
19 * Button with index 2 is pressed at time 5, so it took 5 - 2 = 3 units of time.
20 * Button with index 3 is pressed at time 9, so it took 9 - 5 = 4 units of time.
21 * Button with index 1 is pressed again at time 15, so it took 15 - 9 = 6 units of time.
22 * </div>
23 * <strong class="example">Example 2:
24 * <div class="example-block">
25 * Input: <span class="example-io">events = [[10,5],[1,7]]</span>
26 * Output: <span class="example-io">10</span>
27 * Explanation:
28 *
29 * Button with index 10 is pressed at time 5.
30 * Button with index 1 is pressed at time 7, so it took 7 - 5 = 2 units of time.
31 * </div>
32 *
33 * Constraints:
34 *
35 * 1 <= events.length <= 1000
36 * events[i] == [indexi, timei]
37 * 1 <= indexi, timei <= 10^5
38 * The input is generated such that events is sorted in increasing order of timei.
39 *
40 */
41pub struct Solution {}
42
43// problem: https://leetcode.com/problems/button-with-longest-push-time/
44// discuss: https://leetcode.com/problems/button-with-longest-push-time/discuss/?currentPage=1&orderBy=most_votes&query=
45
46// submission codes start here
47
48impl Solution {
49 pub fn button_with_longest_time(events: Vec<Vec<i32>>) -> i32 {
50 0
51 }
52}
53
54// submission codes end
55
56#[cfg(test)]
57mod tests {
58 use super::*;
59
60 #[test]
61 fn test_3386() {
62 }
63}
64
Back
© 2025 bowen.ge All Rights Reserved.