Class assignment problem

Can you please help me build the logic, I tried generating permutations but couldn’t do it. Please help!!

Hello @div_yanshu07 i think you should approaching it in the correct way actually there are 2 ways in which i have done this question one is the fibonacci way and the other is the way which we can do by DP.
In the dp way we will check for the recusrion calls and then there we will also check if there are not two consecutive b’s if there are 2 consecutive b’s then we will send the a in the recusrion call and otherwise we will make two recursion calls for the both ‘a’ and ‘b’.
Here for your reference i am attaching both the codes.



if you have any doubt you can ask here:
Happy Learning!!

I haven’t done dp properly. Can you explain me the intuition behind the fibonacci one?

do you know the fibonacci pattern if you know then you can easily be able to judge that it is forming fibonccai pattern it is just this approach. like if we have 2 numbers then then answer will be formed is +1 of that fibonacci pattern.

Yeah, I know fibonacci pattern but why are you passing n+2 from the main function.

Hello @div_yanshu07 it was just different appraoch see this if you are not able to understand why i was passing n+2 then you can understand from this :
https://ide.codingblocks.com/s/393731 this was because when n is 1 then also we have 1 2 option to place them seprately just to add for that test case we are doung that.
https://ide.codingblocks.com/s/393731
Happy Learning!!

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.