3550. Smallest Index With Digit Sum Equal to Index Easy

@problem@discussion
#Array#Math



1/**
2 * [3550] Smallest Index With Digit Sum Equal to Index
3 *
4 * You are given an integer array nums.
5 * Return the smallest index i such that the sum of the digits of nums[i] is equal to i.
6 * If no such index exists, return -1.
7 *  
8 * <strong class="example">Example 1:
9 * <div class="example-block">
10 * Input: <span class="example-io">nums = [1,3,2]</span>
11 * Output: <span class="example-io">2</span>
12 * Explanation:
13 * 
14 * 	For nums[2] = 2, the sum of digits is 2, which is equal to index i = 2. Thus, the output is 2.
15 * </div>
16 * <strong class="example">Example 2:
17 * <div class="example-block">
18 * Input: <span class="example-io">nums = [1,10,11]</span>
19 * Output: <span class="example-io">1</span>
20 * Explanation:
21 * 
22 * 	For nums[1] = 10, the sum of digits is 1 + 0 = 1, which is equal to index i = 1.
23 * 	For nums[2] = 11, the sum of digits is 1 + 1 = 2, which is equal to index i = 2.
24 * 	Since index 1 is the smallest, the output is 1.
25 * </div>
26 * <strong class="example">Example 3:
27 * <div class="example-block">
28 * Input: <span class="example-io">nums = [1,2,3]</span>
29 * Output: <span class="example-io">-1</span>
30 * Explanation:
31 * 
32 * 	Since no index satisfies the condition, the output is -1.
33 * </div>
34 *  
35 * Constraints:
36 * 
37 * 	1 <= nums.length <= 100
38 * 	0 <= nums[i] <= 1000
39 * 
40 */
41pub struct Solution {}
42
43// problem: https://leetcode.com/problems/smallest-index-with-digit-sum-equal-to-index/
44// discuss: https://leetcode.com/problems/smallest-index-with-digit-sum-equal-to-index/discuss/?currentPage=1&orderBy=most_votes&query=
45
46// submission codes start here
47
48impl Solution {
49    pub fn smallest_index(nums: Vec<i32>) -> i32 {
50        0
51    }
52}
53
54// submission codes end
55
56#[cfg(test)]
57mod tests {
58    use super::*;
59
60    #[test]
61    fn test_3550() {
62    }
63}
64

Back
© 2026 bowen.ge All Rights Reserved.