Count number of binary strings

I have tried this question using recursion but I am getting TLE. Can I get some hint to optimize my code?

Use DP to avoid tle.
Bottom is easy to implement.

Can it be solved using bit manipulation?

I am not able to think this problem approach using DP. Can you please help me.

for (int i = 1; i < n; i++)
{
a[i] = a[i-1] + b[i-1];
b[i] = a[i-1];
}

In array a , we store if last element was 0.
In array b , we store if last element was 1.

Just return a[n-1]+b[n-1]

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.