I’ getting wrong answer in my code.Could anyone please tell me why it’s giving wrong answer.
This is the question link.
Below is my code.
using namespace std;
int l = 0,k = 0;
for(int i = 0; A[i] != ‘\0’; ++i)
if(A[i] != B[i])
while(A[i] != ‘\0’ && A[i] != B[i])
if(A[i] == ‘\0’)
Can you please provide the link to your submission? Nevermind, got it.
A testcase for which your code fails
The output is 9, but it’s supposed to be 5.
Remember, the answer should never exceed the length of A, as you can perform an operation the whole string.
I had the same problem in the contest. Though I came up with the answer 45 minutes later after working out quite a lot. Look at the editorial to the problem, its really nice.
And yes, first try then look at the editorial.
Ummmm… that’s not the only case in his problem, you are right, but there is another case. For example look at the following example.
Output According To You
Take the first 3 and the last one.
Total Length = 4
Islands = 2
Answer = 4 * 2 = 8
I never mentioned the logic for the solution
I just said that the output can never exceed the length of the string
Ya, my bad…misread your post.