Cant understand logic properly

houldn’t we should update ans to 0 whenever we increment left???and we should calculate the maximum value of ans.
also count[str[l] - ‘a’]–;
how this line is perfectly decrementing the value>k in count array.
This is the code ,please see https://ide.codingblocks.com/s/226002

Hey @sagar_aggarwal,

As per what i have understood from your doubt,
the str will contain only contain two characters ‘a’ and ‘b’.
and the count array has only two indexes 0 and 1.
0 will store the count of ‘a’ and 1 of ‘b’.

So, doing str[l] - ‘a’ will give the index of the character at l and doing count[str[l] - ‘a’]--; will decrement the count.

Hope, this would help.

we have to decrement value of that index in count array who’s value>k right?
how str[l]-‘a’ is giving that index whos value>k?
also,when min(count[0], count[1]) > k we had our first solution right?
then why we havent update our ans value and keep track of max value of ans in some other variable??

Hey @sagar_aggarwal,

I would suggest you to dry run this code for an explain to understand the code better.