FastPrepFirst Strict Local Minimum

First Strict Local Minimum

ZipRecruiter logoZipRecruiter● EasyFULLTIMENEW GRADOA
Learn

Problem statement

You are given an integer array numbers. Inspect only positions that have both a left and a right neighbor.

Return the smallest index i such that numbers[i] is strictly less than both numbers[i - 1] and numbers[i + 1]. Return -1 if no such index exists.

Function

firstStrictLocalMinimum(numbers: int[]) → int

Examples

Example 1

numbers = [1,2,3,4]return = -1

No interior value is smaller than both neighbors.

Example 2

numbers = [1,3,1,2,5]return = 2

At index 2, value 1 is less than 3 and 2; it is the first qualifying index.

Constraints

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

More ZipRecruiter problems

See ZipRecruiter hiring insights
public int firstStrictLocalMinimum(int[] numbers) {
    // Write your code here.
}
numbers[1,2,3,4]
expected-1
Checking account…