We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Anyone know what change is needed to only return the number of odd solutions?
Eg given the coins [1,2,5] and amount 5.
The solutions are:
[1,1,1,1,1]
[2,111]
[2,2,1]
[5]
There are four solutions, but only three odd solutions.
I'm tearing my hair out trying to solve this.
def make_change(coins, n):
lookup = [1] + [0] * n
coins_used_list = []
coins_used_counter = 0
for coin in coins:
for amount in range(n+1-coin):
lookup[amount+coin] += lookup[amount]
return lookup[n]
make_change(coins = [1,2,5], n = 5)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
DP: Coin Change
You are viewing a single comment's thread. Return to all comments →
Anyone know what change is needed to only return the number of odd solutions? Eg given the coins [1,2,5] and amount 5. The solutions are: [1,1,1,1,1] [2,111] [2,2,1] [5] There are four solutions, but only three odd solutions. I'm tearing my hair out trying to solve this.
def make_change(coins, n): lookup = [1] + [0] * n coins_used_list = [] coins_used_counter = 0 for coin in coins: for amount in range(n+1-coin): lookup[amount+coin] += lookup[amount] return lookup[n]
make_change(coins = [1,2,5], n = 5)