FastPrepSearch a Valley Array

Search a Valley Array

Bloomberg LP logoBloomberg LP● MediumNEW GRADPHONE SCREENONSITE INTERVIEW
Learn

Problem statement

nums contains distinct values, strictly decreasing through one minimum and strictly increasing afterward. Return the index of target, or -1 if absent, in O(log n) time.

Function

searchValley(nums: int[], target: int) → int

Examples

Example 1

nums = [10,4,3,2,5,6,8]target = 3return = 2

3 occurs on the decreasing side before the minimum 2.

Constraints

  • 1 <= nums.length <= 10^5.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public int searchValley(int[] nums, int target) {
  // Write your code here.
}
nums[10,4,3,2,5,6,8]
target3
expected2
Checking account…