Intermediate Level
Implement the method searchRotatedArray that finds a target in a rotated sorted array.
A rotated sorted array is sorted but shifted at one pivot. Return the zero-based index of target.
The task is designed to test careful handling of edge cases, not only the most common input.
- Use only the first
sizeelements. - Return
-1if the target is absent. - The test cases use distinct values.
Use binary search by identifying which half of the current range is sorted.