LeetCode 153: Find Minimum in Rotated Sorted Array
Solution Guide for LeetCode 153: Finding the Lowest in a Rotated Sorted Array
I'm Varchasv, a Data Engineer working on enterprise data integration.
Currently on a 90-problem challenge to level up my technical skills and switch to a more development-focused role.
What I'm doing:
- Solving 2 Leetcode problems daily (SQL + DSA).
- Blogging about each problem.
- Building in public.
My Goal - Land a better data engineering role by mid-2026.
Follow my journey !!
Date: February 05, 2026
Category: Arrays
Time Taken: 30 minutes
Difficulty: Medium
Problem Statement
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.
Link: Find Minimum in Rotated Sorted Array
Solution 1:
The first solution that came to mind is to look for a value that is greater than the next value. Since the array is rotated, there will always be a break in the ascending order.
Wherever we find this break, the next value that disrupts the order will be the minimum value, as that's how the array is rotated.
If we don't find any breaks in the array, it means the array is sorted, and we can simply return the first value.
The issue with this solution is that we need an
O(log N)solution, but this approach isO(N)because of the for loop.
Solution Code
class Solution:
def findMin(self, nums: List[int]) -> int:
for index, value in enumerate(nums):
if index != len(nums) - 1 and value > nums[index + 1]:
return nums[index + 1]
return nums[0]
Complexity:
Time: O(N) Space: O(1)
Solution 2 (Binary Search):
Since the array was originally sorted, we can use a modified Binary Search to find the minimum element.
We will place the left pointer at the start and the right pointer at the end of the array. Then, we'll use a while loop with the condition
left < right. Inside the loop, we'll calculate the mid value.If the value at the mid pointer is greater than the value at the right pointer, it means the smaller sorted part of the array is on the right side of mid, so we'll move the left pointer to
mid + 1.If the value at mid is not greater than the value at the right pointer, it means the right side is sorted normally, and the minimum value must be on the left side of the array, so we'll move the right pointer to mid.
The loop will end when
left == right. At this point, there is only one value left, and that will be the minimum value.
Solution Code:
class Solution:
def findMin(self, nums: List[int]) -> int:
left = 0
right = len(nums) - 1
while left < right:
mid = left + (right - left) // 2
# Sorted on the right side
if nums[mid] > nums[right]:
left = mid + 1
else:
right = mid
return nums[left]
Complexity:
Time: O(logN) Space: O(1)
Key Takeaway: If we need to search for some value in a sorted array the problem usually requires a Binary Search.
Pattern: Binary Search
Series: 90 Days of Data Engineering Progress: 35/90 problems completed
Tags: #DEQuest #LeetCode #Python #DataEngineering #BuildInPublic