Sanket and string approach

https://ide.codingblocks.com/s/60954 i am here using my logic for all character it showing tle please suggest me better solution please help in debuging

help in the debug the code

This is not resolved

Hi Neeraj, please try using Huffman Coding here.

Hey Neeraj,

you are not supposed to solve this problem for all the 26 characters as its mentioned in the problem that there will be only 2 characters in the string either ‘a’ or ‘b’.

You can solve this problem with help of two pointers. Let the first pointer is l and the second pointer is r. Then for every position l we will move right end r until on the substring si,si + 1… sr it is possible to make no more than k swaps to make this substring beautiful. Then we need to update the answer with length of this substring and move l to the right.

thanks but I after found my mistake i use this technique which is you now suggesting with two pointer approach. appreciate your effort