Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug Report for find-target-in-rotated-sorted-array #3966

Open
jimmylin91 opened this issue Mar 27, 2025 · 0 comments
Open

Bug Report for find-target-in-rotated-sorted-array #3966

jimmylin91 opened this issue Mar 27, 2025 · 0 comments

Comments

@jimmylin91
Copy link

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

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

The test cases didn't consider the edge case as below.
The code I submitted can be accepted, but the algorithm cannot handle every edge case.
For example:
nums = [3, 5, 6, 0, 1, 2]
target = 5
The algorithm couldn't handle it, however, NeetCode accepted the code.

Image
Image

class Solution:
def search(self, nums: List[int], target: int) -> int:
l, r = 0, len(nums) - 1
result = -1

    while l <= r:
        if nums[l] == target:
            result = l
        elif nums[r] == target:
            result = r

        m = l + ((r - l) // 2)
        if nums[m] > target:
            if nums[r] > nums[m]:
                r = m - 1
            else:
                l = m + 1
        elif nums[m] < target:
            if nums[l] < nums[m]:
                l = m + 1
            else:
                r = m - 1
        else:
            result = m
            break

    return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant