The O(log n) requirement is basically telling you binary search, but the rotation breaks the usual assumption that one side is always smaller.
Use a modified binary search that determines which half is sorted at each step. Compare the target with the sorted half to decide which half to search next. This maintains O(log n) time complexity.
Pro tip: Clearly explain the condition for identifying the sorted half and how it guides the search. Mention edge cases like empty array or single element to show thoroughness.
Set left and right pointers to the start and end of the array.
While left <= right, compute mid and check if it's the target.
Determine if the left half (from left to mid) is sorted by comparing nums[left] and nums[mid].
If left half is sorted, check if target lies within its range; if so, search left, else search right. Otherwise, do the symmetric check for the right half.
If loop ends without finding target, return -1.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.