Skip to main content
Back to problems
#2057
Easy Algorithms

Smallest index with equal value

Array
73.1% acceptance
Feb 25, 2026
457
145
Given a 0-indexed integer array nums, return the smallest index i of nums such that i mod 10 == nums[i], or -1 if such index does not exist. x mod y denotes the remainder when x is divided by y.

Solution

Rust
Time O(n)
Space O(1)
LeetCode
solution.rs
impl Solution {
  pub fn smallest_equal(nums: Vec<i32>) -> i32 {
    for (i, &v) in nums.iter().enumerate() {
      if (i as i32) % 10 == v {
        return i as i32;
      }
    }
    -1
  }
}