Search in Rotated Sorted Array

Medium · Binary Search · Array · Binary Search

Problem

nums was sorted ascending with distinct values, then rotated left at some unknown pivot — so [0,1,2,4,5,6,7] might arrive as [4,5,6,7,0,1,2].

Return the index of target, or -1. Your solution must run in O(log n).

Examples

Input: nums = [4,5,6,7,0,1,2], target = 0
Output: 4
Input: nums = [4,5,6,7,0,1,2], target = 3
Output: -1

Not present.

Input: nums = [1], target = 0
Output: -1

Constraints

Approaches

Related problems

Start free on Cariara · Coding problems · System design studio

Starting Python
No results yet.

          
↑↓ move ↵ open esc close

Labs

Loading labs…

Run with your own input

Starting Python

Loading Python…