Problem
Ask
Submissions

Problem: Search in Rotated Sorted Array II

Medium
30 min
Explore how to apply modified binary search to find an integer target in a rotated sorted array containing duplicates. Understand the problem constraints and develop an efficient solution that minimizes search operations without knowing the pivot index.

Statement

You are required to find an integer value target in an array arr of non-distinct integers. Before being passed as input to your search function, arr has been processed as follows:

  • It has been sorted in non-descending order.

  • It has been rotated around some pivot kk, such that, after rotation, it looks like this: [nums[k], nums[k+1], ..., nums[n-1], nums[0], nums[1], ..., nums[k-1]]. For example, [10, 30, 40, 42, 42, 47, 78, 90, 901], rotated around pivot k=5k=5 becomes [47, 78, 90, 901, 10, 30, 40, 42, 42].

Return TRUE if t exists in the rotated, sorted array arr, and FALSE otherwise, while minimizing the number of operations in the search.

Note: In this problem, the value of kk is not passed to your search function.

Constraints

  • 11 \leq arr.length 1000\leq 1000

  • 104-10^4 \leq arr[i] 104\leq 10^4

  • arr is guaranteed to be rotated at some pivot index.

  • 104-10^4 \leq t 104\leq 10^4

Problem
Ask
Submissions

Problem: Search in Rotated Sorted Array II

Medium
30 min
Explore how to apply modified binary search to find an integer target in a rotated sorted array containing duplicates. Understand the problem constraints and develop an efficient solution that minimizes search operations without knowing the pivot index.

Statement

You are required to find an integer value target in an array arr of non-distinct integers. Before being passed as input to your search function, arr has been processed as follows:

  • It has been sorted in non-descending order.

  • It has been rotated around some pivot kk, such that, after rotation, it looks like this: [nums[k], nums[k+1], ..., nums[n-1], nums[0], nums[1], ..., nums[k-1]]. For example, [10, 30, 40, 42, 42, 47, 78, 90, 901], rotated around pivot k=5k=5 becomes [47, 78, 90, 901, 10, 30, 40, 42, 42].

Return TRUE if t exists in the rotated, sorted array arr, and FALSE otherwise, while minimizing the number of operations in the search.

Note: In this problem, the value of kk is not passed to your search function.

Constraints

  • 11 \leq arr.length 1000\leq 1000

  • 104-10^4 \leq arr[i] 104\leq 10^4

  • arr is guaranteed to be rotated at some pivot index.

  • 104-10^4 \leq t 104\leq 10^4