Hi, I have got run error in 2 test cases. Can you guys please look into my code?
SanketAndStrings Run Error
Hello @Kinjal
You misunderstood the problem statement somewhere.
Here you can find the detailed explanation of the problem statement.
Let me know if you still need any help.
Sir, I see your code but why you increment βiβ if we have to change βbβ to βaβ. But you increment βiβ for both cases inside while loop. Why? So, when I have no more βkβ, then we send it to the else part where while loop is there.
> else {
while (i <= j) { if (a[i] == 'b') i++; else { i++; break; } } m = max(m, j-i+1); }
So this condition will execute, but inside that loop every time you increment βiβ, why? I dont get that part. Can you kindly tell me about that?
Sir, I did some changes in my approach so can you kindly look into my code?
I just want to know, how can I improve my logic if still my approach is so time consuming and weak. In most of the time my logic is failed and give TLE or run error and my lines of codes also going bigger. So, am I doing something wrong!!! Please let me know.
Letβs take an example
aaabbbababb 3
Here when I am at index 7, I see that from the start I have got 4 bβs but I can only change at most 3 βbβ to βaβ
So I search for a βbβ from the start and remove it from the length that I am considering
Here first I will get an βaβ at index 0
Then an βaβ at index 1 i++
Then an βaβ at index 2 i++
Then a βbβ at index 3 i++
I do i++ and stop at 4 because from index 4 to 7 there are 3 βbβ again only which I can change to βaβ.
You can call me bhaiya.
When you write
str[x] = βaβ // The index βxβ doesnβt exist so it is wrong. Rather write str+=βaβ
Also define string1 and string2 internally so that they are reset to empty strings in each iteration
I have modified your code and marked the changes
Here is the modified code
Let me know if you still need any help.
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.