EasyNo. 2057
Smallest Index With Equal Value — LeetCode 2057 Python Solution
- Topics
- Array
- Reading time
- 2 min
- Source
- leetcode.com
The problem
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.
Example
- Input
- nums = [0,1,2]
- Output
- 0
- Explanation
- i=0: 0 mod 10 = 0 == nums[0].
Python solution
class Solution:
def smallestEqual(self, nums: List[int]) -> int:
for i, x in enumerate(nums):
if i % 10 == x:
return i
return -1Complexity
- Time
- O(n)where n is the length of the array
- Space · auxiliary
- O(1)
Related problems
| No. | Problem | Difficulty |
|---|---|---|
| 0057 | Insert Interval | Medium |
| 0228 | Summary Ranges | Easy |
| 0485 | Max Consecutive Ones | Easy |
| 0665 | Non-decreasing Array | Medium |
| 0674 | Longest Continuous Increasing Subsequence | Easy |
| 0699 | Falling Squares | Hard |
Frequently asked questions
- How hard is LeetCode 2057. Smallest Index With Equal Value?
LeetCode 2057. Smallest Index With Equal Value is rated Easy on LeetCode.
- What is the time complexity of LeetCode 2057. Smallest Index With Equal Value?
The Python solution on this page runs in O(n), where n is the length of the array.
- What is the space complexity of LeetCode 2057. Smallest Index With Equal Value?
The Python solution on this page uses O(1) auxiliary space.
- What topics does LeetCode 2057. Smallest Index With Equal Value cover?
LeetCode 2057. Smallest Index With Equal Value is tagged Array on LeetCode.