Make sure you print the output of each test case in a new line. What you’re lacking, is a printf ("\n") character at the end of your loop (to make the result of next test case in new line).
Here I think that the output of the give testcase can be different also.
as mention in the testcase
Input:
1
WBWB
WBBB
Output:
BWBW
as mentioned here that the maximum hamming distance is 7 but is we are taking a string ‘BWWW’ it also have the hamming distance is 7 so why it can not be the correct output??
New here please help.
I am not an expert in java. But I can say that you have created Z[] correctly. The answer is Z[] itself. I have no idea what you have done after the forloop to create Z[] as I am not familiar with the syntax of java.
Is it really required? I mean, I don’t know. I think we can simply print each character. The result will be same if we print a complete string or individual characters one by one without any space.
In Java concatenating String takes more time as each time it creates a new instance of String. You can use StringBuilder in Java for concatenation the string or print each character.
First of all, why are you taking so small string? The maximum length will be 10^5, so you should take at least 1 greater than the maximum possible length.
The second point is, your code will not work. In the case when a[i]!=b[i] the output should be B, but in your code, it will give W.
It is actually not 1.01s…it is >=1.01s…that means, the system has stopped the code after 1.01s because the code is taking more than 1s to give the output.