3471. Find the Largest Almost Missing Integer Easy
1/**
2 * [3471] Find the Largest Almost Missing Integer
3 *
4 * You are given an integer array nums and an integer k.
5 * An integer x is almost missing from nums if x appears in exactly one subarray of size k within nums.
6 * Return the largest almost missing integer from nums. If no such integer exists, return -1.
7 * A subarray is a contiguous sequence of elements within an array.
8 *
9 * <strong class="example">Example 1:
10 * <div class="example-block">
11 * Input: <span class="example-io">nums = [3,9,2,1,7], k = 3</span>
12 * Output: <span class="example-io">7</span>
13 * Explanation:
14 *
15 * 1 appears in 2 subarrays of size 3: [9, 2, 1] and [2, 1, 7].
16 * 2 appears in 3 subarrays of size 3: [3, 9, 2], [9, 2, 1], [2, 1, 7].
17 * <li index="2">3 appears in 1 subarray of size 3: [3, 9, 2].
18 * <li index="3">7 appears in 1 subarray of size 3: [2, 1, 7].
19 * <li index="4">9 appears in 2 subarrays of size 3: [3, 9, 2], and [9, 2, 1].
20 *
21 * We return 7 since it is the largest integer that appears in exactly one subarray of size k.
22 * </div>
23 * <strong class="example">Example 2:
24 * <div class="example-block">
25 * Input: <span class="example-io">nums = [3,9,7,2,1,7], k = 4</span>
26 * Output: <span class="example-io">3</span>
27 * Explanation:
28 *
29 * 1 appears in 2 subarrays of size 4: [9, 7, 2, 1], [7, 2, 1, 7].
30 * 2 appears in 3 subarrays of size 4: [3, 9, 7, 2], [9, 7, 2, 1], [7, 2, 1, 7].
31 * 3 appears in 1 subarray of size 4: [3, 9, 7, 2].
32 * 7 appears in 3 subarrays of size 4: [3, 9, 7, 2], [9, 7, 2, 1], [7, 2, 1, 7].
33 * 9 appears in 2 subarrays of size 4: [3, 9, 7, 2], [9, 7, 2, 1].
34 *
35 * We return 3 since it is the largest and only integer that appears in exactly one subarray of size k.
36 * </div>
37 * <strong class="example">Example 3:
38 * <div class="example-block">
39 * Input: <span class="example-io">nums = [0,0], k = 1</span>
40 * Output: <span class="example-io">-1</span>
41 * Explanation:
42 * There is no integer that appears in only one subarray of size 1.
43 * </div>
44 *
45 * Constraints:
46 *
47 * 1 <= nums.length <= 50
48 * 0 <= nums[i] <= 50
49 * 1 <= k <= nums.length
50 *
51 */
52pub struct Solution {}
53
54// problem: https://leetcode.com/problems/find-the-largest-almost-missing-integer/
55// discuss: https://leetcode.com/problems/find-the-largest-almost-missing-integer/discuss/?currentPage=1&orderBy=most_votes&query=
56
57// submission codes start here
58
59impl Solution {
60 pub fn largest_integer(nums: Vec<i32>, k: i32) -> i32 {
61 0
62 }
63}
64
65// submission codes end
66
67#[cfg(test)]
68mod tests {
69 use super::*;
70
71 #[test]
72 fn test_3471() {
73 }
74}
75Back
© 2026 bowen.ge All Rights Reserved.