🔗 Try This Problem First
Platform: LeetCode
Problem Number: 153
👉 Practice here: https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/
🧠 Problem Understanding
You are given a sorted array that has been rotated between 1 and n times.
Example:
Original sorted array:
After rotation:
Your task:
👉 Return the minimum element from this rotated array.
👉 Time complexity must be O(log n).
👉 All elements are unique.
🔍 Key Observation
In a rotated sorted array:
- The array is divided into two sorted halves.
- The minimum element is the pivot point where rotation happened.
- One half will always be sorted.
- We can use Binary Search to find where the sorted order breaks.
Example:
🚀 Approach 1: Brute Force (Not Allowed by Constraint)
Idea
Scan entire array and track minimum.
Complexity
- Time: O(n)
- Space: O(1)
❌ Not acceptable because problem requires O(log n).
🚀 Approach 2: Binary Search (Optimal – O(log n))
💡 Core Idea
Compare nums[mid] with nums[right].
There are only two possibilities:
Case 1: nums[mid] > nums[right]
Minimum is in right half.
Move left pointer:
Case 2: nums[mid] <= nums[right]
Minimum is in left half including mid.
Move right pointer:
✅ Optimized Code
📊 Dry Run
Input:
| Step | l | r | mid | nums[mid] | Action |
| 1 | 0 | 6 | 3 | 7 | 7 > 2 → l = 4 |
| 2 | 4 | 6 | 5 | 1 | 1 <= 2 → r = 5 |
| 3 | 4 | 5 | 4 | 0 | 0 <= 1 → r = 4 |
| Stop | 4 | 4 | - | - | Return nums[4] |
✅ Output = 0
🧩 Why This Works
- If middle element is greater than rightmost, rotation point is to the right.
- If middle element is smaller than or equal to rightmost, minimum is on the left side.
- We continuously shrink search space until
l == r. - That position holds the minimum element.
⏱ Time & Space Complexity
| Metric | Value |
| Time Complexity | O(log n) |
| Space Complexity | O(1) |
Because:
- We eliminate half of the array each iteration.
- No extra space is used.
⚠️ Important Edge Cases
- Array size = 1
- Already sorted (no visible rotation)
- Rotation at last position
🎯 Interview Insight
This problem teaches:
- Modified Binary Search
- Identifying sorted halves
- Handling rotated arrays
- Understanding pivot logic
This is a very common FAANG interview question and often appears in variations like:
- Search in Rotated Sorted Array
- Find Peak Element
- Minimum in Rotated Array with Duplicates
🏁 Final Takeaway
- Brute force works but violates constraint.
- Binary search is the correct approach.
- Compare
midwithright. - Shrink search space until pointers meet.
- Return
nums[l]ornums[r].




