Find the Smallest Magic Index
Updated
Problem statement
An index i is magic when values[i] == i using zero-based indexing.
Return the smallest magic index, or -1 when no such index exists.
Function
smallestMagicIndex(values: int[]) → intExamples
Example 1
values = [-1,0,2,5]return = 2Index two is the first position equal to its value.
Example 2
values = [1,2,3]return = -1No position equals its zero-based index.
Constraints
0 <= values.length <= 100000-1000000000 <= values[i] <= 1000000000
More ZipRecruiter Phone Screen questions
- Neighboring Record IDsPHONE SCREEN · Seen May 2026
- Restaurant Vote LeadersPHONE SCREEN · ONSITE INTERVIEW · Seen Feb 2026
- Most Frequent Word across Grouped ArraysPHONE SCREEN · Seen Sep 2024
- Starting Value with the Longest Collatz ChainPHONE SCREEN · Seen Apr 2022
- Classify an Alien Dictionary OrderingPHONE SCREEN · ONSITE INTERVIEW · Seen Mar 2022
- Multiset Intersection of Three ListsPHONE SCREEN · Seen Feb 2022
- Website Pair with the Most Common VisitorsPHONE SCREEN · Seen Nov 2021
- Center-Outward Number SpiralPHONE SCREEN · Seen Jun 2021
- Missing Ranges within Inclusive BoundsPHONE SCREEN · Seen Feb 2021
- Fibonacci Number with Constant Extra SpacePHONE SCREEN · Seen Mar 2017
Similar questions at other companies
- Best Time to Buy and Sell StockMeta · PHONE SCREENMeta interview questions
- Lazy Filter over a GeneratorSquarepoint Capital · PHONE SCREENSquarepoint Capital interview questions
- Second Largest Distinct ElementAmazon · PHONE SCREEN
- Automation Pipeline, Part 1: Single WorkerPlaid · PHONE SCREENPlaid interview questions
- Best Stock Trade with Buy and Sell DaysGoogle · PHONE SCREENGoogle interview questions
- Search and Format ContactsAdyen · PHONE SCREENAdyen interview questions
- Majority ElementByteDance · PHONE SCREENByteDance interview questions
- Detect a Straight FlushTemu · PHONE SCREENTemu interview questions
- Recommend Films from Viewers Who Watched Everything You DidBloomberg LP · PHONE SCREENBloomberg LP interview questions
- Total Years of Work ExperienceLinkedIn · PHONE SCREENLinkedIn interview questions