Sanket_and_strings

https://ide.codingblocks.com/s/56539
what is the problem in this code
i know this is not an efficient solution but still

https://ide.codingblocks.com/s/55482

what is a thought process behind this solution

Hey Mudit, its pretty simple as you will be having only 2 two chars in the string a and b, so in this code you are just maintaining the minimum changes you are making for getting the longest required string till the particular index.

Hey, my code is passing just the first test case.
Kindly help me out where i am wrong.

link to my code :-

https://ide.codingblocks.com/s/57921

Hey Tanay, in your code your if - elseif conditions will not give the correct length of the substring.
check for this case
input:
7
aaabababbababbbbbbbaaaaaabbbbababbababbbaaa

your code’s output:
30

but the expected output:
19

Thanks for the reply, can you suggest some alternate approach to this problem @sanjeetboora

Hey Tanay, Yes sure, here I am sharing my approach you can refer refer this.