Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Search in Rotated Sorted Array

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Search in Rotated Sorted Array. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Given a rotated sorted array of distinct integers, implement a function that returns the index of a target value or -1 if it is not present. The solution must run in O(log n) time, so a linear scan is not acceptable.

Constraints

  • 1 <= nums.length <= 10^5
  • All values in nums are distinct
  • nums is sorted in ascending order and rotated at an unknown pivot
  • -10^4 <= nums[i], target <= 10^4
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output