‹ DS&A interview · Socratic
DSA · Binary Search · #73

Find Minimum in Rotated Sorted Array

Module 59 · difficulty 3/5·30:00starts on first keystroke

Suppose an array of length `n` sorted in ascending order with **unique** elements is rotated between `1` and `n` times. Given the resulting rotated array `nums`, implement `findMin(nums)` that returns the **minimum element** of the array. You must write an algorithm that runs in `O(log n)` time.

Examples
  • nums = [3,4,5,1,2] 1The original array was [1,2,3,4,5] rotated 3 times.
  • nums = [4,5,6,7,0,1,2] 0The original array was [0,1,2,4,5,6,7] rotated 4 times.
  • nums = [11,13,15,17] 11The original array was rotated n times (back to sorted).
Constraints
  • · n == nums.length
  • · 1 <= n <= 5000
  • · -5000 <= nums[i] <= 5000
  • · All integers of nums are unique.
  • · nums is sorted and rotated between 1 and n times.
Session phases
A · Clarify
B · Approach
C · Complexity
D · Edges
E · Code
F · Tradeoff
G · Score
Phase A — Clarify
Ask questions about input bounds, types, and edge constraints.
Ask the coach clarifying questions about the problem.
When you've covered this phase, advance to the next.