Magicsheet logo

Smallest Index With Equal Value

Easy
25%
Updated 8/1/2025

Asked by 1 Company

Topics

Smallest Index With Equal Value

What is this problem about?

The "Smallest Index With Equal Value" interview question is a very basic array iteration task. You are given a 0-indexed integer array nums. You need to find the smallest index i such that i % 10 == nums[i]. If no such index exists, return -1. This "Smallest Index With Equal Value coding problem" is designed to test basic coding literacy and familiarity with the modulo operator.

Why is this asked in interviews?

Google and other companies use this for very early technical screens or as part of a larger set of easy questions to ensure a candidate can follow simple instructions and write a clean loop. It tests if you understand how to use the modulo operator correctly and if you can early-exit from a loop once the condition is met.

Algorithmic pattern used

This follows the "Array and Enumeration interview pattern". You simply iterate through the array from left to right. Since you need the smallest index, the first index that satisfies the condition i % 10 == nums[i] is your answer. This is an O(n) time complexity solution with O(1) space.

Example explanation

Array: [0, 1, 2, 4, 5]

  • Index 0: 0 % 10 = 0. nums[0] = 0. Match! Return 0. Array: [7, 8, 3, 5, 2, 1]
  • Index 0: 0 % 10 = 0 != 7
  • Index 1: 1 % 10 = 1 != 8
  • Index 2: 2 % 10 = 2 != 3
  • Index 3: 3 % 10 = 3 != 5
  • Index 4: 4 % 10 = 4 != 2
  • Index 5: 5 % 10 = 5 != 1 Result: -1.

Common mistakes candidates make

The biggest mistake is overcomplicating the logic or using a complex data structure. Some might also forget to return -1 if no index is found. Another minor error is using the wrong index in the modulo operation (e.g., nums[i] % 10 == i instead of i % 10 == nums[i]).

Interview preparation tip

For "EASY" problems, focus on clarity and edge cases. Ensure your loop bounds are correct and that you handle the "not found" case gracefully. This "Smallest Index With Equal Value interview question" is a great way to practice the "early exit" strategy in loops.

Similar Questions