Skip to content

Bug Report for remove-duplicates-from-sorted-array #4936

@martel-darin

Description

@martel-darin

Bug Report for https://neetcode.io/problems/remove-duplicates-from-sorted-array

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

My golang solution is an exact match for the python solution yet it fails when submitting.

Python solution listed on site:

def removeDuplicates(self, nums: list[int]) -> int:
    n = len(nums)
    l = r = 0
    while r < n:
        nums[l] = nums[r]
        while r < n and nums[r] == nums[l]:
            r += 1
        l += 1
    return l

The solution I came up with in Go:

func removeDuplicates(nums []int) int {
    l, r := 0, 0
    for r < len(nums) {
        nums[l] = nums[r]
        for r < len(nums) && nums[r] == nums[l] {
            r++
        }
        l++
    }
    return l
}

Test case that is failing is 24 of 24. All other 23 passed.

If this is the best you guys can do I honestly expect a refund.

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