Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Search in Rotated Sorted Array
00:00
5 left

Search in Rotated Sorted Array

EasyPython

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
Interviewer

Your question is Search in Rotated Sorted Array. Start with the requirements in the Question tab.

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.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.