Not getting ans

question – if set{1,3,5} steps are allowed in this stair case problem then i write a recursive code which is not working, please tell me the wrong approach and how to correct my code.

my code-https://ide.codingblocks.com/s/257643

and why some recursive code show TLE sometimes

@shivamgoel150 1 base case was missing (commented in your code)


if(n<0) return 0; (this is because if n passed is 2 then n-3 and n-5 will make it neg and you are not doing anything if no becomes neg)
recursive code is always bruteforce code like the code you have written takes o(3^n) as for every number you are dividing into three smaller parts . thats why it lead to tle and to modify it dp is used.
dont forget to hit like and mark resolved if cleared :smiley: