I knew this problem but still fumbled the edge cases mid-implementation.
Use a modified binary search that determines which half of the array is sorted at each step, then decides whether the target lies in that sorted half. This achieves O(log n) time by eliminating half the search space each iteration.
Pro tip: Clarify upfront whether the array contains duplicates, as that changes the algorithm's complexity and edge cases. Also, mention that you can find the pivot first and then do a standard binary search, but the single-pass approach is more elegant and efficient.
Ask about duplicates, array size, and whether the rotation is by a known amount. Confirm that the array is sorted in ascending order before rotation.
Set left = 0 and right = n-1. While left <= right, compute mid and compare arr[mid] with target.
Check if the left half (arr[left] <= arr[mid]) is sorted. If so, check if target lies within that range; if yes, move right = mid-1, else left = mid+1. Otherwise, the right half must be sorted, so check if target lies there and adjust pointers accordingly.
If arr[left] == arr[mid] == arr[right], decrement right and increment left to skip duplicates, which may degrade to O(n) in worst case.
If target is found, return mid. If the loop ends without finding it, return -1.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.