Skip to content

Bug Report for coin-change #6052

Description

@EmilyXu0427

Bug Report for https://neetcode.io/problems/coin-change

Please describe the bug below and include any steps to reproduce the bug or screenshots if possible.
The following is memoization method to resolve the problem and passing leetcode submission. But it fails neetcode submission.

class Solution:
def coinChange(self, coins: List[int], amount: int) -> int:
# memoization
solns = [None] * (amount + 1)

    def dfs(amount):
        if amount < 0:
            return float("+inf")

        if solns[amount] != None:
            return solns[amount]

        if amount == 0:
            solns[amount] = 0
        else:
            res = float("+inf")
            for c in coins:
                temp = 1 + dfs(amount - c)
                res = min(res, temp)
            solns[amount] = res
        return solns[amount]

    res = dfs(amount)     
    return res if res < float("+inf") else -1

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