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

EFanZh / LeetCode / 43870638803

20 Nov 2026 02:52PM UTC coverage: 99.786% (-0.02%) from 99.807%
43870638803

push

github

EFanZh
Add problem 4032: Longest Subarray With at Most K Distinct Prime Factors

316 of 316 branches covered (100.0%)

Branch coverage included in aggregate %.

63 of 63 new or added lines in 2 files covered. (100.0%)

33 existing lines in 28 files now uncovered.

125922 of 126193 relevant lines covered (99.79%)

7297.53 hits per line

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

93.33
/src/problem_3698_split_array_with_minimum_difference/iterative.rs
1
pub struct Solution;
2

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

5
impl Solution {
6
    pub fn split_array(nums: Vec<i32>) -> i64 {
4 ✔
7
        let nums = nums.into_iter().map(i32::cast_unsigned).collect::<Vec<_>>();
4 ✔
8
        let mut prev_1 = 0_u64;
4 ✔
9
        let mut candidate = 0_u64;
4 ✔
10
        let mut iter = nums.iter().copied();
4 ✔
11

12
        let mut prev_2 = u64::from(loop {
4 ✔
13
            if let Some(num) = iter.next() {
12 ✔
14
                if (prev_1 as u32) < num {
12 ✔
15
                    prev_1 = u64::from(num);
8 ✔
16
                    candidate += prev_1;
8 ✔
17
                } else {
18
                    break num;
4 ✔
19
                }
20
            } else {
21
                return (candidate - prev_1).abs_diff(prev_1).cast_signed();
×
22
            }
23
        });
24

25
        candidate = candidate.wrapping_sub(prev_2);
4 ✔
26

27
        for num in iter {
4 ✔
28
            if num < prev_2 as u32 {
4 ✔
29
                prev_2 = u64::from(num);
3 ✔
30
                candidate = candidate.wrapping_sub(prev_2);
3 ✔
31
            } else {
32
                return -1;
1 ✔
33
            }
34
        }
35

36
        let mut result = candidate.cast_signed().unsigned_abs();
3 ✔
37

38
        if prev_1 != prev_2 {
3 ✔
39
            result = result.min(candidate.wrapping_sub(prev_1 * 2).cast_signed().unsigned_abs());
3 ✔
UNCOV
40
        }
×
41

42
        result.cast_signed()
3 ✔
43
    }
4 ✔
44
}
45

46
// ------------------------------------------------------ snip ------------------------------------------------------ //
47

48
impl super::Solution for Solution {
49
    fn split_array(nums: Vec<i32>) -> i64 {
4 ✔
50
        Self::split_array(nums)
4 ✔
51
    }
4 ✔
52
}
53

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

© 2026 Coveralls, Inc