Skip to content

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

@yhangliu

Description

@yhangliu

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.

Using the example solution returns "Output Limit Reached":
class Solution:
def combinationSum2(self, candidates: List[int], target: int) -> List[List[int]]:
res = []
candidates.sort()

    def dfs(i, cur, total):
        if total == target:
            res.append(cur.copy())
            return
        if total > target or i == len(candidates):
            return

        cur.append(candidates[i])
        dfs(i + 1, cur, total + candidates[i])
        cur.pop()


        while i + 1 < len(candidates) and candidates[i] == candidates[i+1]:
            i += 1
        dfs(i + 1, cur, total)

    dfs(0, [], 0)
    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