112. Search in rotated sorted array-II

Given an integer array nums, sorted in ascending order (may contain duplicate values) and a target value k. Now the array is rotated at some pivot point unknown to you. Return True if k is present and otherwise, return False.

Example 1:

Input : nums = [7, 8, 1, 2, 3, 3, 3, 4, 5, 6], k = 3

Output: True

Explanation: The element 3 is present in the array. So, the answer is True.

Example 2:

Input : nums = [7, 8, 1, 2, 3, 3, 3, 4, 5, 6], k = 10

Output: False

Explanation:The element 10 is not present in the array. So, the answer is False.

Now Your Turn!

Pick the correct output for the given input

Input : nums = [7, 8, 1, 2, 3, 3, 3, 4, 5, 6], k = 7

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  •   1 <= nums.length <= 104
  •   -104 <= nums[i] <= 104
  •   nums is guaranteed to be rotated at some pivot.
  •   -104 <= k <= 104

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

Fun Facts

0
class Solution {
public:
bool searchInARotatedSortedArrayII(vector<int> &nums, int k) {
}
};
Test Case

Input:

K
Nums