FastPrepFind the Smallest Magic Index

Find the Smallest Magic Index

ZipRecruiter logoZipRecruiter● EasyFULLTIMEPHONE SCREEN

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[]) → int

Examples

Example 1

values = [-1,0,2,5]return = 2

Index two is the first position equal to its value.

Example 2

values = [1,2,3]return = -1

No position equals its zero-based index.

Constraints

  • 0 <= values.length <= 100000
  • -1000000000 <= values[i] <= 1000000000

More ZipRecruiter Phone Screen questions

Similar questions at other companies

ZipRecruiter interview experiences

All ZipRecruiter interview questionsSee ZipRecruiter hiring insights
Saved
class Solution {
    public int smallestMagicIndex(int[] values) {
        // Write your code here.
    }

}
Checking account…