Class assignment


is it correct how to use backtracting in it

@vanisinghal0201,you don’t necessarily need to use backtracking unless you want to print the strings. if you want to count sequences consisting of a and b and no consiquetive b then you can simply have a character variable in the function parameter that store the previous charater , now in every call you can check for the case that

  1. if previous character was ‘a’ then you can have two cases in one in which you set current charater as ‘a’ and another in which you set your current character as ‘b’
  2. if previous character was b then you can’t have current character as a b thus u have only one case i.e setting current character as a

refer this code :- https://ide.codingblocks.com/s/237753

in case you wonder how to print such strings
refer this :- https://ide.codingblocks.com/s/237754

In case of any doubt feel free to ask :slight_smile:
mark your doubt as resolved if u got the answer

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.