Can you check if my code for this problem is correct or not?

hello @isingh
yeah it is correct

Can you also explain the logic behind the base case? I did it by trial and error

@isingh
if n is 1 then ways are two (0,1)

if n is 0 then there is no way so we also count this as one way(i know it is weired).

instead use these base case if they make sense ->
if n=1 return 2 ; // ( 0,1)
if n=2 return 3 ; // (00,01,10)

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.