Back to problems Sign in to unlock
Leetcode
Easy
Arrays
Smallest Stable Index I
Find the smallest index where the value equals the index.
Acceptance 0%
Problem Statement
Given an integer array nums, find the smallest index i such that nums[i] == i. If no such index exists, return -1.
This is a simple index-value matching problem: scan the array and look for the first position where the element is equal to its own index.
Input Format
- An integer array
nums. - The array is zero-indexed.
Output Format
- Return the smallest index
isuch thatnums[i] == i. - If no such index exists, return
-1.
Constraints
0 <= nums.length- Values in
numsare integers. - Use a solution that is at least linear in the array size unless a stronger property is available.
Examples
Sample cases returned by the problem API.
Example 1
Input
nums = [0,2,3,4]
Output
0
Explanation
At index 0, nums[0] = 0, so the smallest stable index is 0.
Example 2
Input
nums = [1,2,3,4]
Output
-1
Explanation
No position has nums[i] == i.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.
Guided hints
Editorial and discussion links
Concept map and variants
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.