FastPrepSearch in Rotated Sorted Array II

Search in Rotated Sorted Array II

Bloomberg LP logoBloomberg LP● MediumNEW GRADPHONE SCREEN
Learn

Problem statement

An integer array was sorted in nondecreasing order and then rotated at an unknown position. The array may contain duplicates.

Given nums and target, return whether target occurs in nums.

Function

search(nums: int[], target: int) → boolean

Examples

Example 1

nums = [2,5,6,0,0,1,2]target = 0return = true

Zero occurs at the rotation boundary.

Example 2

nums = [2,5,6,0,0,1,2]target = 3return = false

Three is absent.

Constraints

  • 1 <= nums.length <= 10^5.
  • All values and target are signed 32-bit integers.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public boolean search(int[] nums, int target) {
    // Write your code here.
}
nums[2,5,6,0,0,1,2]
target0
expectedtrue
Checking account…