Class Assignment : Getting TLE in test cases

I am applying brute force here. Please review my code and guide me with the efficient optimization.
link : https://ide.geeksforgeeks.org/7cO2RwE85h

@ayushjain.aj300 hey ayush this question require a dynamic approach. try with bottom up approach.

Sir, I thought of going with bottom up approach, but I was unable to develop that logic. Please help me with the logic of bottom up approach.

@ayushjain.aj300 hey ayush
the sample one is given like
test case =3
n=1
n=2
n=3
make a function n_digits and pass the value of n in the function
inside the function declare two array inside the function int a[n],int b[n]
and mark index 0 of both the array is 1
like
a[0]=1;
b[0]=1;
now apply a loop from i=1 to upto <=n
and do
a[i]=a[i-1]+b[i-1];
b[i]=a[i-1];
and return
a[n-1]+b[n-1];
do dry run on this logic

Very well explained sir. Thanks a lot. :slight_smile: