Back to Practice
#0113

Search in Rotated Sorted Array

MediumDSA25 min20 XP

Problem

Given a rotated sorted array with distinct values and a target, return the target index or -1.

Why This Matters

This problem tests whether you understand binary-search invariants, not just memorized mid calculation.

Function Signature

def search_rotated(nums, target):

Examples

Example 1
Input[4,5,6,7,0,1,2], target = 0
Output4

0 is found at index 4 even though the array is rotated.

Constraints

  • Return the requested value exactly.
  • Handle the stated edge cases.
  • Keep the solution readable.
CodePython
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core example
Input[4,5,6,7,0,1,2], target = 0
Expected4

0 is found at index 4 even though the array is rotated.

Hidden Test Categories
not rotatedsingle elementtarget in left sorted half