Skip to content

Bug Report for find-minimum-in-rotated-sorted-array #5136

@gauthamb7

Description

@gauthamb7

Bug Report for https://neetcode.io/problems/find-minimum-in-rotated-sorted-array

Please describe the bug below and include any steps to reproduce the bug or screenshots if possible.

My input :
nums=[2, 2, 2, 0, 1, 2]

Expected output should be 0 but I'm getting 2...

This was your solution which is giving correct output as 0 but expected output is shown as 2
class Solution:
def findMin(self, nums: List[int]) -> int:
res = nums[0]
l, r = 0, len(nums) - 1

    while l <= r:
        if nums[l] < nums[r]:
            res = min(res, nums[l])
            break

        m = (l + r) // 2
        res = min(res, nums[m])
        if nums[m] >= nums[l]:
            l = m + 1
        else:
            r = m - 1
    return res

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions