Skip to content

Fix coin change #2571

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Oct 23, 2020
23 changes: 16 additions & 7 deletions dynamic_programming/coin_change.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,29 @@
"""


def dp_count(S, m, n):
def dp_count(S, n):
"""
>>> dp_count([1, 2, 3], 3, 4)
>>> dp_count([1, 2, 3], 4)
4
>>> dp_count([1, 2, 3], 3, 7)
>>> dp_count([1, 2, 3], 7)
8
>>> dp_count([2, 5, 3, 6], 4, 10)
>>> dp_count([2, 5, 3, 6], 10)
5
>>> dp_count([10], 1, 99)
>>> dp_count([10], 99)
0
>>> dp_count([4, 5, 6], 3, 0)
>>> dp_count([4, 5, 6], 0)
1
>>> dp_count([1, 2, 3], -5)
0
>>> dp_count([4, 5, 6], -4)
0
>>> dp_count([2, 5, 3, 6], -10)
0
>>> dp_count([4], -4)
0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
>>> dp_count([1, 2, 3], -5)
0
>>> dp_count([4, 5, 6], -4)
0
>>> dp_count([2, 5, 3, 6], -10)
0
>>> dp_count([4], -4)
0
>>> dp_count([1, 2, 3], -5)
0

I think 1 test case for this is enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@poyea You said to add some more test cases in the previous comment?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean to test the < 0 line, one test case is enough. You may add some larger test cases too to demonstrate the correctness.

"""

if n < 0:
return 0
# table[i] represents the number of ways to get to amount i
table = [0] * (n + 1)

Expand Down