Skip to content
Programmingoneonone
Programmingoneonone

Learn everything about programming

  • Home
  • 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
Programmingoneonone
Programmingoneonone

Learn everything about programming

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 *

Are you a student and stuck with your career or worried about real-time things, and don't know how to manage your learning phase? Which profession to choose? and how to learn new things according to your goal, and land a dream job. Then this might help to you.

Hi My name is YASH PAL, founder of this Blog and a Senior Software engineer with 5+ years of Industry experience. I personally helped 40+ students to make a clear goal in their professional lives. Just book a one-on-one personal call with me for 30 minutes for 300 Rupees. Ask all your doubts and questions related to your career to set a clear roadmap for your professional life.

Book session - https://wa.me/qr/JQ2LAS7AASE2M1

Pages

  • About US
  • Contact US
  • Privacy Policy

Follow US

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