https://ide.codingblocks.com/s/61656
It is showing run-error when I am submitting, but it is running fine on ide.
SanketandStringsProblem
I am trying to use combination in this problem.
yr logic is wrong try for
1
ababababab
is there any other way of approaching this problem?
Hi Anushka, yes. Here is the hint to the approach: Let us take two pointers- L and R. Then for every position L, we will move towards the right end R, until on the substring si.si + 1… sR it is possible to make no more than k swaps to make this substring beautiful. Then we need to update the answer with length of this substring and move L to the right.
Can you explain with an example. I am not able to understand the meaning of making the string beautiful and the concept of subarray.
use stack ans the TC of the program should not be o(n^2)
Hi Anushka, according to the question,
Sanket has a string consisting of only a and b as the characters. Sanket describes perfectness of a string as the maximum length substring of equal characters. Sanket is given a number K which denotes the maximum number of characters he can change. Find the maximum perfectness he can generate by swapping no more than k characters.
Basically, there is a string which consists of only a and b. A substring is a contiguous sequence of characters within a string. Our aim is to generate substrings of a and b by swapping characters such that the lengths of substrings of either a or b is maximum possible. The only constraint we have here is that only k swaps are allowed. So, you have to tell the maximum possible length of the substrings that can be generated. By swapping, we mean that a can be replaced by b and b can be replaced by a.
For example:
Consider the following string: abba and k = 2
So, we can make only two swaps
abba (swaps = 0)
aaba (swaps = 1)
aaaa (swaps = 2)
Thus, the maximum length of substring is 4.
Consider the string: ababab and k=2
ababab (swaps = 0)
aaabab (swaps =1)
aaaaab (swaps = 2)
Thus, the maximum length of substring is 5.
I hope the question is clear now.
yes the question is clear now.
Thank You
https://ide.codingblocks.com/s/64863
I changed the code but still i am not getting correct ans after submission, although I am getting output in the ide.
Can you tell me which possible case I am missing?
Hi, check the order of input. You have to take the integer first and then the string. Also, you are always starting with the beginning of the string, what if the longest length can be achieved somewhere in the middle of the string?