https://practice.geeksforgeeks.org/problems/consecutive-1s-not-allowed/0
plz tell how to memoize the top down approach in my code…
https://practice.geeksforgeeks.org/problems/consecutive-1s-not-allowed/0
plz tell how to memoize the top down approach in my code…
hello @S19LPPP0202
dont use string because it will give u memory limit error.
f(n) =f(n-1) (when we put 0 at nth position)
f(n) = f(n-2) (when we put 1 at nth position ,n-2 because we have to place 0 at n-1 th position)
so combining thw two result
we can say
f(n)=f(n-1) +f(n-2)
now memoisation is simple .just use a linear array. and intiialise it with -1.
add base case if n=1 return 2. if n==2 return 3
But u plz provide the memoized version of my top down code …I prefer to code in top down manner rather than bottom up because too down is more intuitive and easy…
What do u mean by string will give memory error??
@S19LPPP0202
have to tried on ur own?
this is very simple recurrence relation that u need to implement for this problem.
using top down or bottom up is totally up to u.
it will take more memory so u might face memory limit exceeded issue.
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.