Optimal Binary Strings Recursion

Here is the code of the above question:- https://ide.codingblocks.com/s/450151, please tell why we taking the way as 1 when length of string is 0. And also please tell whether the implementation of the question is correct or not?

Hello @Sakshi2004 yes your code is correct but i think as the test cases are larger so you have to memoise it .

@Sakshi2004 no when length is 0 then it should return 0 only.
for length 1 we have two options 0 or 1
for length 2 we have 3 options
00
01
10
correct base will be
if(n<=0)return 0;
if(n<=2) return n+1;

Yeah Thanks, got the point.

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.