Diwali Offer!Flat 20% OFF
Enroll Now
PrakalpanaLive online tech training

59. Find Minimum in Rotated Sorted Array

MediumDay 17 of 60Binary Search

An array of distinct integers was sorted in ascending order and then rotated some number of times (possibly zero), for example [0,1,2,4,5,6,7] could become [4,5,6,7,0,1,2]. Return the smallest element. Your solution must be O(log n).

Example 1
Input: nums = [3,4,5,1,2]
Output: 1
Example 2
Input: nums = [4,5,6,7,0,1,2]
Output: 0
Example 3
Input: nums = [11,13,15,17]
Output: 11
Rotated a full cycle, so it is sorted again.
Constraints
  • 1 <= nums.length <= 5000
  • -5000 <= nums[i] <= 5000
  • All values are distinct
Hints
Frequently asked at: Amazon, Microsoft, Meta, Goldman Sachs
Ctrl + Enter runs the examples

Not sure what to learn next?

A 1-on-1 session with an industry mentor and a roadmap built for you. How it works

  1. 1Discuss your goals
  2. 2Get a personal plan
  3. 3Start learning
Book for β‚Ή200/ 30 min