educative.io

When n = 0, answer should be zero instead 1

When n=0, why answer is 1, it should be zero, as we can’t make sum = 0 with 1, 3 or 4.

https://www.educative.io/courses/grokking-dynamic-programming-patterns-for-coding-interviews/NE52PnMY376

@Umapada_Manna Yes, we can’t make sum 0 with 1, 3, or 4. But we all know for 0, there are no possible ways to express 0. That’s why we can say that this code works for numbers n=1 to onwards. If you want to get the correct number of ways for n=1,2,3,4,… then we’ve to set if(n==0) return 1 as our base condition.