Leetcode 153: Find Minimum in Rotated Sorted Array

grid47
grid47
Exploring patterns and algorithms
Oct 22, 2024 5 min read

A rotating array with a glowing highlight marking the minimum element.
Solution to LeetCode 153: Find Minimum in Rotated Sorted Array Problem

Given a sorted array of unique elements, rotated between 1 and n times, find the minimum element in this array.
Problem
Approach
Steps
Complexity
Input: The input is a sorted array of unique integers which is rotated between 1 and n times.
Example: nums = [6,7,9,10,2,3,4]
Constraints:
• 1 <= n <= 5000
• -5000 <= nums[i] <= 5000
• All elements in the array are unique.
Output: The output should be the minimum element in the rotated sorted array.
Example: 2
Constraints:
• The array will always be rotated between 1 and n times.
Goal: To find the minimum element, use a binary search approach that reduces the search space in each step.
Steps:
• Initialize two pointers: start and end of the array.
• Find the middle element and compare it with the rightmost element.
• If the middle element is greater than the rightmost element, the minimum must be in the right half, so move the start pointer to mid + 1.
• Otherwise, move the end pointer to mid.
• Repeat this process until the start pointer equals the end pointer, which will be the minimum element.
Goal: The input array is sorted but rotated between 1 and n times.
Steps:
• 1 <= n <= 5000
• -5000 <= nums[i] <= 5000
• All elements in the array are unique.
Assumptions:
• The array is sorted and rotated.
• The array has at least one element.
Input: nums = [6,7,9,10,2,3,4]
Explanation: The array was originally [2,3,4,6,7,9,10] and was rotated 4 times. The minimum element is 2.

Input: nums = [10,11,13,15,18,20,1]
Explanation: The array was originally [1,10,11,13,15,18,20] and was rotated 6 times. The minimum element is 1.

Link to LeetCode Lab


LeetCode Solutions Library / DSA Sheets / Course Catalog
comments powered by Disqus