Grokking Dynamic Programming Patterns for Coding Interviews
Ask Author
Back to course home

0% completed

Vote For New Content
Any idea why '+1' is added to count1 i.e. while including the coin at the curren...

Lucifer

Mar 3, 2022

Any idea why '+1' is added to count1 i.e. while including the coin at the current index?

1

0

Comments
Comments
A
Avinash Agarwal4 years ago

That is because we are saying there is way to reach this total while including this coin.

R
Ray 3 years ago

The count1 = res + 1 is really hard to visualize.

I'm not sure I really understand it (as it goes through the recursive layers).

In the nested, recursive calls, it either returns 0 (total was found) or MAX_VALUE (total not found) from the coin(s).

How does count1...

G
George 3 years ago

I still don't understand why we add 1 when we're including current coin.

How are we certain that whenever coins[i]

G
George 3 years ago

ok nvm i think i partially get it.

We add 1 because we are including the current coin to the minimum count at the remaining amount (ie. dp[index][t-denominations[index]].

On this page