Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Search in Rotated Array II

Easy Acceptance 79.00% Points 20.00

Given a rotated sorted array of integers that may contain duplicates and a target value, return true if the target exists in the array, otherwise return false. The array was originally sorted in non-decreasing order and then rotated at an unknown pivot. Due to duplicates, the search process may require checking both halves in some cases.

Examples
Example 1

Example 1

Input: nums = [2,5,6,0,0,1,2], target = 0

Output: true

Explanation: The target value 0 exists in the rotated array.

Example 2

Example 2

Input: nums = [2,5,6,0,0,1,2], target = 3

Output: false

Explanation: The target value 3 does not exist in the array.

Example 3

Example 3

Input: nums = [1,1,1,1,1], target = 1

Output: true

Explanation: All elements are the same and equal to the target, so it exists in the array.

Hints
Hint 1
N/A
Constraints
  • 1 = nums.length = 105
  • -104 = nums[i], target = 10
Companies
Apple
Topics
Binary Search
Solution.cs C#JavaPythonC++Javascript

Unlock the code editor

Sign in to write, run, and submit your solution against the full test suite.

  • Run code against sample & hidden test cases
  • Save submissions and track your streak
  • Compare with editorial & community solutions