Can i get a hint to solve this problem

can i get a hint to solve this problem

You can use the 2 pointer approach.
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

Reference code https://ide.codingblocks.com/s/226002

can you explain the logic with a example

?? @pratyush63 sorry if you are busy

You can refer this.
Read this article. If after that you have any doubt then you can ask

https://www.geeksforgeeks.org/maximum-length-substring-having-all-same-characters-after-k-changes/#:~:text=When%20count%20will%20be%20equal,finally%20return%20the%20maximum%20length.

Dry run the code with example cases and you will get how its working


getting wrong o/p

??? https://ide.codingblocks.com/s/286631

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.