
Problem
Solution
Submissions
Minimum in Rotated Sorted Array
Certification: Intermediate Level
Accuracy: 0%
Submissions: 0
Points: 10
Write a C program to find the minimum element in a rotated sorted array. The array was originally sorted in ascending order, then rotated at some pivot unknown to you beforehand. All elements in the array are unique. You must write an algorithm that runs in O(log n) time.
Example 1
- Input: nums = [3, 4, 5, 1, 2]
- Output: 1
- Explanation: The original array was [1, 2, 3, 4, 5] rotated 3 times.
Example 2
- Input: nums = [4, 5, 6, 7, 0, 1, 2]
- Output: 0
- Explanation: The original array was [0, 1, 2, 4, 5, 6, 7] rotated 4 times.
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
- Time Complexity: O(log n)
- Space Complexity: O(1)
Editorial
My Submissions
All Solutions
Lang | Status | Date | Code |
---|---|---|---|
You do not have any submissions for this problem. |
User | Lang | Status | Date | Code |
---|---|---|---|---|
No submissions found. |
Solution Hints
- Use binary search since the array has rotated sorted property
- Compare the middle element with the rightmost element
- If middle element is greater than rightmost, minimum is in the right half
- If middle element is less than rightmost, minimum is in the left half including middle
- Continue until you find the minimum element
- The minimum element is where the rotation occurs