Neural Mastery
← Back to Practice

Search in a Rotated Sorted Array

Difficulty: Medium · Pattern: Binary Search · Concept: General Coding (DSA) — Core Patterns to Drill

Find the Rotation Point located the minimum in a rotated sorted array. This problem is genuinely harder, not a rename: find a target value's index directly, in one O(logn)O(\log n) binary search — without first finding the rotation point as a separate step.

The key insight: at any mid, comparing arr[mid] to arr[lo] tells you which half is the normally-sorted one (the rotation point is only ever in one half or the other). Once you know which half is sorted, you can cleanly check whether the target falls inside that sorted half's range — and if it does, search there; if it doesn't, the target must be in the other half.

Your task: implement search_rotated(arr, target), returning the target's index, or -1 if it isn't present. arr has no duplicates.

Implement it yourself
assert search_rotated([4, 5, 6, 7, 0, 1, 2], 0) == 4 assert search_rotated([4, 5, 6, 7, 0, 1, 2], 5) == 1 assert search_rotated([4, 5, 6, 7, 0, 1, 2], 3) == -1 assert search_rotated([1], 1) == 0 assert search_rotated([1], 0) == -1

Next: Longest Increasing Subsequence

Last updated Sep 5, 2026Edit this pageReport an issue