MEDIUM NC#31 Blind #7 Binary Search
153. Find Minimum in Rotated Sorted Array
📖 Problem
Suppose an array of length n sorted in ascending order is rotated between 1 and n times. Given the sorted rotated array nums of unique elements, return the minimum element of this array. You must write an algorithm that runs in O(log n) time.
🧠 Visual Learning Aid
1 Model the input into the right structure
2 Choose the core technique and invariant
3 Execute step-by-step with a sample
4 Validate complexity and edge cases
JS/TS Refreshers
- •Array methods (`push`, `pop`, `shift`, `slice`)
- •Object/Map/Set usage patterns
- •Function parameter and return typing
- •Midpoint overflow-safe math
- •Loop invariants
- •Monotonic condition design
Logical Thinking Concepts
- •Define invariants before coding
- •Check edge cases first (`[]`, single element, duplicates)
- •Estimate time/space before implementation
- •Apply Binary Search reasoning pattern
💡 Approach
- → In rotated sorted array, minimum is at pivot point where order breaks
- → Compare mid with right to decide which half contains minimum
- → If nums[mid] > nums[right], min is in right half
- → If nums[mid] <= nums[right], min is in left half (including mid)
- → Time: O(log n), Space: O(1)
🧭 Prerequisites
🛠️ Hints & Pitfalls
Hints
- •In rotated sorted array, minimum is at pivot point where order breaks
- •Compare mid with right to decide which half contains minimum
- •If nums[mid] > nums[right], min is in right half
Common Pitfalls
- •If nums[mid] <= nums[right], min is in left half (including mid)
- •Time: O(log n), Space: O(1)
🧪 Test Cases
Hidden tests on submit: 3
Test Case 1
Not run Input:
findMin([3,4,5,1,2]); Expected:
1 Test Case 2
Not run Input:
findMin([4,5,6,7,0,1,2]); Expected:
0 Test Case 3
Not run Input:
findMin([11,13,15,17]); Expected:
11 📝 Code Editor
📤 Output