3678. Smallest Absent Positive Greater Than Average Easy
1/**
2 * [3678] Smallest Absent Positive Greater Than Average
3 *
4 * You are given an integer array nums.
5 * Return the smallest absent positive integer in nums such that it is strictly greater than the average of all elements in nums.
6 * The average of an array is defined as the sum of all its elements divided by the number of elements.
7 *
8 * <strong class="example">Example 1:
9 * <div class="example-block">
10 * Input: <span class="example-io">nums = [3,5]</span>
11 * Output: <span class="example-io">6</span>
12 * Explanation:
13 *
14 * The average of nums is (3 + 5) / 2 = 8 / 2 = 4.
15 * The smallest absent positive integer greater than 4 is 6.
16 * </div>
17 * <strong class="example">Example 2:
18 * <div class="example-block">
19 * Input: <span class="example-io">nums = [-1,1,2]</span>
20 * Output: <span class="example-io">3</span>
21 * Explanation:
22 *
23 * The average of nums is (-1 + 1 + 2) / 3 = 2 / 3 = 0.667.
24 * The smallest absent positive integer greater than 0.667 is 3.
25 * </div>
26 * <strong class="example">Example 3:
27 * <div class="example-block">
28 * Input: <span class="example-io">nums = [4,-1]</span>
29 * Output: <span class="example-io">2</span>
30 * Explanation:
31 *
32 * The average of nums is (4 + (-1)) / 2 = 3 / 2 = 1.50.
33 * The smallest absent positive integer greater than 1.50 is 2.
34 * </div>
35 *
36 * Constraints:
37 *
38 * 1 <= nums.length <= 100
39 * -100 <= nums[i] <= 100
40 *
41 */
42pub struct Solution {}
43
44// problem: https://leetcode.com/problems/smallest-absent-positive-greater-than-average/
45// discuss: https://leetcode.com/problems/smallest-absent-positive-greater-than-average/discuss/?currentPage=1&orderBy=most_votes&query=
46
47// submission codes start here
48
49impl Solution {
50 pub fn smallest_absent(nums: Vec<i32>) -> i32 {
51 0
52 }
53}
54
55// submission codes end
56
57#[cfg(test)]
58mod tests {
59 use super::*;
60
61 #[test]
62 fn test_3678() {
63 }
64}
65Back
© 2026 bowen.ge All Rights Reserved.