What is wrong in my code ? COOK107B/EXAM1

Problem Link : https://www.codechef.com/COOK107B/problems/EXAM1

My Solution : https://www.codechef.com/viewsolution/24929356

Any help will be appreciated.

1 Like

You don’t need the first loop and condition, there will be nothing but a,b,c,d,n! Moreover you are thinking hard. You can just compare the right answer and chef’s answer by using a loop. If it is n just continue and otherwise just skip the index for once. Have a look at this code: https://www.codechef.com/viewsolution/24911732

1 Like

your code is giving wrong answer on this test case
2
AB
CB

ANSWER SHOULD BE 0
YOUR ANSWER IS 1

1 Like

The 56th line of ur code also counts the test case when the wrong answer in u[i] is N. This should be avoided to get the correct answer

1 Like

I tried with that approach too. I though I had misread the question or maybe overthought.

Another unsuccessful solution which satisfies your testcase : https://www.codechef.com/viewsolution/24920828

1 Like

I already have a condition which will bypass that condition on line 39.

1 Like

4
ABAB
ACNB

THIS IS YET ANOTHER TEST CASE ON WHICH UR CODE IS NOT WORKING

2 Likes

It will not bypass the condition… Actually it will consider both conditions and that is where u r getting wrong…

You can check my solution for further improvement…
https://www.codechef.com/viewsolution/24912747

You need to put f=0 before continue in line 40
The Very first condition in loop x== n-1 is not right

Got it.
Thanks mate!

1 Like

Got it! Thanks mate!