• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

EFanZh / LeetCode / 22088472836

25 Feb 2026 03:34PM UTC coverage: 99.882% (-0.002%) from 99.884%
22088472836

push

github

EFanZh
Add problem 3386: Button with Longest Push Time

296 of 296 branches covered (100.0%)

Branch coverage included in aggregate %.

37 of 40 new or added lines in 2 files covered. (92.5%)

121999 of 122144 relevant lines covered (99.88%)

7772.31 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.32
/src/problem_3386_button_with_longest_push_time/iterative.rs
1
pub struct Solution;
2

3
// ------------------------------------------------------ snip ------------------------------------------------------ //
4

5
use std::cmp::Ordering;
6

7
impl Solution {
8
    pub fn button_with_longest_time(events: Vec<Vec<i32>>) -> i32 {
2✔
9
        let mut max_index = 0;
2✔
10
        let mut max_duration = 0;
2✔
11
        let mut prev_index = 0;
2✔
12
        let mut prev_time = 0;
2✔
13

14
        events
2✔
15
            .iter()
2✔
16
            .filter_map(|event| <[i32; 2]>::try_from(event.as_slice()).ok())
6✔
17
            .map(|event| event.map(i32::cast_unsigned))
6✔
18
            .for_each(|[index, time]| {
6✔
19
                let duration = time - prev_time;
6✔
20

21
                match duration.cmp(&max_duration) {
6✔
22
                    Ordering::Less => {}
1✔
23
                    Ordering::Equal => {
NEW
24
                        if index < max_index {
×
NEW
25
                            max_index = index;
×
NEW
26
                        }
×
27
                    }
28
                    Ordering::Greater => {
5✔
29
                        max_duration = duration;
5✔
30
                        max_index = index;
5✔
31
                    }
5✔
32
                }
33

34
                prev_index = index;
6✔
35
                prev_time = time;
6✔
36
            });
6✔
37

38
        max_index.cast_signed()
2✔
39
    }
2✔
40
}
41

42
// ------------------------------------------------------ snip ------------------------------------------------------ //
43

44
impl super::Solution for Solution {
45
    fn button_with_longest_time(events: Vec<Vec<i32>>) -> i32 {
2✔
46
        Self::button_with_longest_time(events)
2✔
47
    }
2✔
48
}
49

50
#[cfg(test)]
51
mod tests {
52
    #[test]
53
    fn test_solution() {
1✔
54
        super::super::tests::run::<super::Solution>();
1✔
55
    }
1✔
56
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc