Out of 3 ,2 testcases are wrong,why?
@Saksham12
Consider this testcase :
Input :
2
aaabbbaaaa
Expected Output :
6
Your Output :
9
Your code is considering all a’s together and all b’s together while we have to consider each window of characters. We should not take a count of all a’s or all b’s together as that would give us wrong answer.
I suggest you to use two pointer approach for this problem.
Alternatively you can use Deque ( if you have done Stacks & Queues in your course ).
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.