Search in Rotated Sorted Array II
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
An array nums was sorted in non-decreasing order (duplicates allowed) and then rotated at some unknown index k, so it now reads nums[k], ..., nums[n-1], nums[0], ..., nums[k-1]. The rotation may be 0, meaning the array could still be fully sorted.
Return true if target occurs in nums, otherwise false.
Try to keep the search logarithmic in the typical case. Duplicates can make it impossible to tell which half is sorted (for example when the left end, middle, and right end are all equal), so the worst case may degrade to O(n); explain how your code handles that case.
Examples
Constraints
- 1 <= nums.length <= 5000
- -10^4 <= nums[i], target <= 10^4
- `nums` is a rotation of a non-decreasing array
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.