Skip to content

Bug Report for combination-target-sum-ii #5456

@samthambad

Description

@samthambad

Bug Report for https://neetcode.io/problems/combination-target-sum-ii

Please describe the bug below and include any steps to reproduce the bug or screenshots if possible.
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
my code fails for this testcase on leetcode but works here, I guess this testcase isnt on neetcode?

my code is this

class Solution:
    def combinationSum2(self, candidates: List[int], target: int) -> List[List[int]]:
        ans = []
        ans_map = []

        def helper(i, acc, arr):
            if acc == target:
                curr_map = Counter(arr)
                print("curr map", curr_map)
                if curr_map not in ans_map:
                    ans_map.append(curr_map)
                    ans.append(arr.copy())
                return
            
            if i >= len(candidates) or acc > target:
                return
            arr.append(candidates[i])
            helper(i+1, acc + candidates[i], arr)
            arr.pop()
            helper(i+1, acc, arr)
        helper(0, 0, [])
        return ans

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