Any hint for this problem?

any hint for this problem??

sure :slight_smile: first try perfectness for a’s and then for b’s,let’s focus how to do for a:
traverse across the given string,so whenever ‘a’ comes your length of consecutive a’s increases, else when b comes you try to make it ‘a’(only if swap is allowed) otherwise there’s no way to continue ahead except free characters from starting until one of b occurs(which was swapped earlier, hence this leaves you with one more swap allowed), now swap this b into a and continue. best datastructure for this can be deque, also perfectness is maximum size of your deque.

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.