The algorithm: Initialize left = , right = n While left <= right: - Compute mid - If nums[mid] == target, return mid - Check which half is sorted: - If nums[left] <= nums[mid], left half is sorted - If target is in [nums[left], nums[mid]), search left - Otherwise, search right - Else, right half is sorted - If target is in (nums[mid], nums[right]], search right - Otherwise, search left Return
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
$ curl repovive.com/roadmaps/maang-interview-prep/binary-search/search-in-rotated-sorted-array-solution
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░███████████████████████████████████████████████████████████████████████████████████████████████████████