Sanket ans strings

yeh question ho ni rha, bta do kese krna hai?
approach bta do bas.

The logic for solving this problem is a simple one, we begin with 2 pointers left and right, we freeze left and increase right till it is possible to make string from left to right of one character once number of different character exceeds k, we move left pointer till it becomes less than k and then we freeze left pointer and move right and this process continues till right reaches n. We do this because this way we can find the maximum solution for each left.

Take two-pointer l and r to mark the left and right index of the string under consideration.
starting from l=0,r=0,max=0,count=0.
repeat until r <n
3.1. increase the count whenever you find a different character(by different we mean if we are forming a string of an only, then b is different).
3.2. while count is greater than k,
3.2.1. decrement the count by one if the element at lth index is different.
3.2.1. increment l.
3.3. Compare max with count for maximum value.
3.4. increment r.

left act as left pointer and i as right pointer

Bhaiya, smajh ni aaya achhi tarah se.

Can you tell me which part of the solution is not clear to you?

#include using namespace std; int main() { int n,B_count,A_count,length; cin>>n; char s[1000000]; cin>>s; int maxim=1; for(int i=0;i<s[i]!=’\0’;i++) { A_count++; B_count++; for(int j=i;j<s[j]!=’\0’;j++) { A_count=0; B_count=0; for(int k=i;k<=j;k++) { length=j-i+1; if(s[k]==β€˜a’) { A_count++; } else { B_count++; } //now for making each substring eqaul we have to swap the characters. int flip_a=length-B_count; int flip_b=length-A_count; if(flip_a<=n && length>=maxim) { maxim=length; } else if( flip_b<=n && length>=maxim) { maxim=length; } } } } cout<<maxim; return 0; } I’d solved this question, sample output is same but test cases are not passing , so can you please check what’s happening?

please share your code through ide.codingblocks.com

Have you Checked?