i’m not able to get from where i have to start , please tell me the approach to solve this problem
Sanket and strings approach
This question can be solved using many approach
I m discussing 2 Pointer Approach
just maintain two values
Lets try to make maximum contiguous b using k swaps
Starting i=0,j=0,swaps_available=k
let say
To maximize contigous b
if(swap_available>=0)
{
… if(character_at_j==b)
… {
…,…increase j;
…}
… else
…{
…,…swap_available–;
…,…increase j;
…}
}
else
{
…if(character_at_i==b)
…{
…,…i++;
…}
…else
…{
…,…swap_available++;
…,…i++;
…}
}
DO same for finding maximum a and print the maximum between these.
Hit like if u get it
2 Likes
But wher edo you calculate the max length in your code?