Given a rotated sorted array of unique integers and a target, return the index of target, or -1 if not found. Must run in O(log n).

Input: nums=[4,5,6,7,0,1,2], target=0 → Output: 4Input: nums=[4,5,6,7,0,1,2], target=3 → Output: -1

Binary search with rotation handling: at each step determine which half is sorted, then check if target falls in that sorted half.

class Solution { public int search(int[] nums, int target) { int lo = 0, hi = nums.length - 1; while (lo <= hi) { int mid = lo + (hi - lo) / 2; if (nums[mid] == target) return mid; if (nums[lo] <= nums[mid]) { // left sorted if (target >= nums[lo] && target < nums[mid]) hi = mid - 1; else lo = mid + 1; } else { // right sorted if (target > nums[mid] && target <= nums[hi]) lo = mid + 1; else hi = mid - 1; } } return -1; } }