478. Search in Rotated Sorted Array (With Duplicates)

MediumBinary SearchBinary SearchArray

Given an array that was sorted in ascending order and then rotated at an unknown pivot, and which may contain duplicates, determine whether a target value exists in the array. Return true if present, otherwise false. Input: '[arr], target'.

Input: '[arr], target'.

Output: Boolean — true or false.

Examples

Example 1
Input: [2,5,6,0,0,1,2], 0
Output: true
Explanation: 0 is present.
Example 2
Input: [2,5,6,0,0,1,2], 3
Output: false
Explanation: 3 is absent.
Example 3
Input: [1], 1
Output: true
Explanation: Single element matches.

Constraints

Asked by

AmazonBloombergPaytmMicrosoftOracleFlipkart
Solve this problem in the editor →