text function search(nums, target): left = 0 right = length(nums) - 1 while left <= right: mid = left + (right - left) / 2 if nums[mid] == target: return mid // Check which half is sorted if nums[left] <= nums[mid]: // Left half is sorted if nums[left] <= target < nums[mid]: right = mid - 1 else: left = mid + 1 else: // Right half is sorted if nums[mid] < target <= nums[right]: left = mid + 1 else: right = mid - 1 return -1 Time complexity: . Still halving the search space. Space complexity: .
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
$ curl repovive.com/roadmaps/maang-interview-prep/binary-search/search-in-rotated-sorted-array-pseudocode
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████████████████████████████████████████████████████████████████████████████████████████████████████