Skip to content
Programmingoneonone
Programmingoneonone
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
    • Cybersecurity
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
  • Work with US
Programmingoneonone
Programmingoneonone

Leetcode Find Minimum in Rotated Sorted Array problem solution

YASH PAL, 31 July 202419 January 2026

In this Leetcode Find Minimum in Rotated Sorted Array problem solution, we have 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.

Leetcode Find Minimum in Rotated Sorted Array problem solution

Leetcode Find Minimum in Rotated Sorted Array problem solution in Python.

class Solution:
    def findMin(self, nums: List[int]) -> int:
        l , r = 1,len(nums)-1
        
        while l<=r:
            m = l + (r-l)//2
            if nums[m]<nums[m-1]:
                return nums[m]
            if nums[m]<nums[0]:
                r = m
            else:
                l = m + 1
                
        return nums[0]

Find Minimum in Rotated Sorted Array problem solution in Java.

public int findMin(int[] nums) {
    return binarySearch(nums,0,nums.length-1);
}
private int binarySearch(int[] nums,int l,int h){
    if(l == h) return nums[l];
    if(l == h-1) return Math.min(nums[l],nums[h]);
    if(nums[l] < nums[h]) return nums[l];
    int m = (l+h)/2;
    if(nums[m] < nums[l] && nums[m] < nums[h]) return binarySearch(nums,l,m); 
    else return binarySearch(nums,m,h);
}

Problem solution in C++.

int findMin(vector<int>& nums) {
        int left=0;
        int right=nums.size()-1;
        int ans=nums[0];
        while(left<=right){
            int mid=(left+right)/2;
            ans=min(ans,nums[mid]);
            if(nums[mid]<nums[right])
                right=mid-1;
            else
                left=mid+1;
        }
        return ans;
    }

Problem solution in C.

int findMin(int* nums, int numsSize) {
    int low = 0,step = numsSize - 1;
    while(step)
    {
        while(low + step >= numsSize||nums[low] > nums[low + step])
            step >>= 1;
        low += step;
    }
    return nums[(low+1)%numsSize];
}

coding problems solutions Leetcode Problems Solutions Leetcode

Post navigation

Previous post
Next post

Leave a Reply

Your email address will not be published. Required fields are marked *

Pages

  • About US
  • Contact US
  • Privacy Policy

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes