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

Leetcode Find Minimum in Rotated Sorted Array II problem solution

YASH PAL, 31 July 202419 January 2026

In this Leetcode Find Minimum in Rotated Sorted Array II problem solution, suppose an array of length n sorted in ascending order is rotated between 1 and n times. For example, the array nums = [0,1,4,4,5,6,7] might become:

  1. [4,5,6,7,0,1,4] if it was rotated 4 times.
  2. [0,1,4,4,5,6,7] if it was rotated 7 times.

Notice that rotating an array [a[0], a[1], a[2], …, a[n-1]] 1 time results in the array [a[n-1], a[0], a[1], a[2], …, a[n-2]].

Given the sorted rotated array nums that may contain duplicates, return the minimum element of this array. You must decrease the overall operation steps as much as possible.

Leetcode Find Minimum in Rotated Sorted Array II problem solution

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

class Solution:
    def findMin(self, nums: List[int]) -> int:
        i=0
        if not nums:return None
        while(i<len(nums)-1 and nums[i+1]>=nums[i]):
            i+=1
        if i==len(nums)-1:i=-1
        return nums[i+1]

Find Minimum in Rotated Sorted Array II problem solution in Java.

int low = 0, high = nums.length-1;
        while(low < high) {
            int mid = (low + high) / 2;
            if(nums[low] > nums[mid]) {
                high = mid;
            }else if(nums[mid] > nums[high]) {
                low = mid + 1;
            }else if(nums[low] < nums[mid]){
                return nums[low];
            }else if(nums[mid] < nums[high]) {
                return nums[mid];
            }else {
                low++;
            }
        }
        
        return nums[low];

Problem solution in C++.

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

Problem solution in C.

int findMin(int* nums, int numsSize) {
    if (numsSize == 1 || nums[0] < nums[numsSize-1]) {
        return nums[0];
    }
    for (int i = numsSize - 1; i > 0; i--) {
        if (nums[i] < nums[i-1]) {
            return nums[i];
        }
    }
}

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