leetcode icon indicating copy to clipboard operation
leetcode copied to clipboard

Bug Report for remove-duplicates-from-sorted-array (go)

Open qbolt opened this issue 2 months ago • 0 comments

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

Issue

The 'Remove duplicates from sorted array' submission (linked above) seems to incorrectly fail on one of the larger input test cases (pasted test case below). I tested the same solution with the same input case on my own system and on leetcode and the solution passes.

Code:

func removeDuplicates(nums []int) int {
    var prev = nums[0]
    var endIndex = 0
    for _, val := range nums[1:] {
        if val != prev {
            endIndex++
            nums[endIndex] = val
            prev = val
        }
    }
    return endIndex + 1
}

Input:

The input for the testcase was too large to paste directly, but it's the case that has each number from -100 to 100 repeated ~100 times each.

Here is a gist with the input for convenience: https://gist.github.com/qbolt/fd5bb13e6eabbc82c9225c31dbfaa96e

qbolt avatar Oct 23 '25 00:10 qbolt