Using recursion i got one test case passed, but i am trying to use top down dp for the same problem, and getting wrong answer always. Help me out
Count Number of Binary Strings DP
@Kishan-Mishra-2464674013761441
Your array initialisation is wrong. If you want to initialise your entire DP array as -1 , initialise it using a loop or the memset function.
Initialising it using the curly bracket as you have only puts the first term as -1 and all the remaining terms get initilialised to 0.
This should resolve the issue of wrong output.
Also I would like to suggest you to use long long int instead of int for the values as you will notice that your answer crosses the limit of int for slightly larger inputs like n >= 50.
1 Like
Thanks a lot. That really helped. All test cases are passed.