3833. Count Dominant Indices Easy

@problem@discussion
#Array#Enumeration



1/**
2 * [3833] Count Dominant Indices
3 *
4 * You are given an integer array nums of length n.
5 * An element at index i is called dominant if: nums[i] > average(nums[i + 1], nums[i + 2], ..., nums[n - 1])
6 * Your task is to count the number of indices i that are dominant.
7 * The average of a set of numbers is the value obtained by adding all the numbers together and dividing the sum by the total number of numbers.
8 * Note: The rightmost element of any array is not dominant.
9 *  
10 * <strong class="example">Example 1:
11 * <div class="example-block">
12 * Input: <span class="example-io">nums = [5,4,3]</span>
13 * Output: <span class="example-io">2</span>
14 * Explanation:
15 * 
16 * 	At index i = 0, the value 5 is dominant as 5 > average(4, 3) = 3.5.
17 * 	At index i = 1, the value 4 is dominant over the subarray [3].
18 * 	Index i = 2 is not dominant as there are no elements to its right. Thus, the answer is 2.
19 * </div>
20 * <strong class="example">Example 2:
21 * <div class="example-block">
22 * Input: <span class="example-io">nums = [4,1,2]</span>
23 * Output: <span class="example-io">1</span>
24 * Explanation:
25 * 
26 * 	At index i = 0, the value 4 is dominant over the subarray [1, 2].
27 * 	At index i = 1, the value 1 is not dominant.
28 * 	Index i = 2 is not dominant as there are no elements to its right. Thus, the answer is 1.
29 * </div>
30 *  
31 * Constraints:
32 * 
33 * 	1 <= nums.length <= 100
34 * 	1 <= nums[i] <= 100​​​​​​​
35 * 
36 */
37pub struct Solution {}
38
39// problem: https://leetcode.com/problems/count-dominant-indices/
40// discuss: https://leetcode.com/problems/count-dominant-indices/discuss/?currentPage=1&orderBy=most_votes&query=
41
42// submission codes start here
43
44impl Solution {
45    pub fn dominant_indices(nums: Vec<i32>) -> i32 {
46        0
47    }
48}
49
50// submission codes end
51
52#[cfg(test)]
53mod tests {
54    use super::*;
55
56    #[test]
57    fn test_3833() {
58    }
59}
60

Back
© 2026 bowen.ge All Rights Reserved.