Tensorum
YouTubeশেখা শুরু করুন
LeetCode 153 · Rotated Sorted Array

Find Minimum in Rotated Sorted Array

LeetCode 153 · মাঝারি · সমাধান, intuition ও ধাপে ধাপে ওয়াকথ্রু

nums[mid] < nums[high] ⇒ high = mid, else low = mid + 1.

মাঝারিArrayBinary Search
LeetCode-এ খুলুন ↗

আমি Find Minimum in Rotated Sorted Array (LeetCode 153) এভাবে সমাধান করেছি — Rotated Sorted Array প্যাটার্নের একটি মাঝারি প্রবলেম। নিচে: intuition, ধাপে ধাপে approach, আমার accepted Python কোড, animated test cases আর line-by-line debugger।

নিচের বিবরণ ইংরেজিতে।

Intuition

Compare mid with the right end. If nums[mid] < nums[high], the right half is sorted and the minimum is at mid or to its left; otherwise the drop — and the minimum — is to the right of mid.

Approach

  1. 1

    low < high loop.

  2. 2

    Right half sorted → high = mid (mid may be the min).

  3. 3

    Otherwise low = mid + 1.

  4. 4

    Return nums[low].

আমি কীভাবে সমাধান করেছি

Binary search on the dropPythonO(log n) time
class Solution:
    def findMin(self, nums: List[int]) -> int:
        #find mini in which half
        low = 0
        high = len(nums)-1
        while low<high:
            mid = (low+high)//2
            if nums[mid]<nums[high]:#remove the right half
                high = mid
            else:
                low = mid+1 #remove the left half
        return nums[low]
স্টেপ-থ্রু লোড হচ্ছে…

Find Minimum in Rotated Sorted Array — সাধারণ প্রশ্ন

Find Minimum in Rotated Sorted Array-এর পেছনে intuition কী?

Compare mid with the right end. If nums[mid] < nums[high], the right half is sorted and the minimum is at mid or to its left; otherwise the drop — and the minimum — is to the right of mid.

Find Minimum in Rotated Sorted Array (LeetCode 153) কীভাবে সমাধান করবেন?

1. low < high loop. 2. Right half sorted → high = mid (mid may be the min). 3. Otherwise low = mid + 1. 4. Return nums[low].

Find Minimum in Rotated Sorted Array-এর time আর space complexity কত?

Time: O(log n)। Space: O(1)। (Accepted approach: Binary search on the drop।)

Find Minimum in Rotated Sorted Array-এ সাধারণ ভুলগুলো কী?

Compare with high, not low — comparing with low fails on an unrotated array.