← Back

πŸŒ€ Twisted Spiral Forest

Search in Rotated Sorted Array

Target

-

Pivot At

-

Current Mid

-

Range

-

Steps

0
πŸ”‘ Key Insight
In a rotated array, ONE HALF is always sorted. Find it, then decide which half to search!
🌲 The Twisted Forest 🌲
L: -
M: -
R: -
Generate a rotated array to start searching!

πŸ“– Search in Rotated Sorted Array

Problem: Array was sorted, then rotated at some pivot. Find target.

Key: At least one half is always sorted!

β€’ If arr[left] ≀ arr[mid] β†’ Left half is sorted

β€’ Otherwise β†’ Right half is sorted

β€’ Check if target is in sorted half, search there; else search other half

Time: O(log n)