Sanket and Strings

I’m using this approach to solve this question, but output is not correct, So can you please check my code and let me know where i’m wrong. Thanks.

https://ide.codingblocks.com/s/296168, please check my code.

Now, sample output is same, but test cases are not passing.

@CODER_JATIN try this test
1
abbb
here answer should be 4(convert first a to b) but your answer is 3.
try to debug for this test.

My answer is same for sample test case.

@CODER_JATIN

this is not sample test case!

bhaiya, approach bta do , kese karu??

@CODER_JATIN
to correct this approach, instead of checking with s[comp]
first check with ‘a’ and then with ‘b’
as in given test

for string from 0 to 3
you checked such that every character can be s0 only!
if you had checked for ‘b’ as well then it would give correct answer,

But it’s O(n^3) ,
think sliding window approach.

bhaiya, sliding window approach to abhi tk kraayi ni prateek bhaiya ne, youtube se dekhlu ek baar?

@CODER_JATIN yes you can, you can also skip this approach for now and retry when done with sliding window.