← Visualizers
Binary Search — Rotated Arrays LeetCode 33

Search in Rotated Sorted Array / visualized

A rotated sorted array isn't sorted end to end — but split at any point, one half always is. At each step, figure out which half of [left, right] is sorted by comparing nums[left] to nums[mid], then check whether the target falls inside that sorted half's range. If it does, search there — otherwise it must be in the other half.

Execution

idle
Press Run to begin.
0 / 0
Speed

Java · running line

left mid right found
O(log n) time · O(1) space  ·  still binary search — just with an extra check for which half is actually sorted before deciding where to look.