Help in debugging - EXAM1

for _ in range(int(input())):
n = int(input())
arr = list(input())
brr = list(input())
bo = [True] * n

count = 0
if arr[0] == brr[0]:
    count += 1
elif brr[0] != 'N':
    bo[0] = False

# print(count)
for i in range(1, n - 1):
    if bo[i - 1]:

        if arr[i] == brr[i]:
            count += 1
        elif brr[i] != 'N':
            bo[i] = False

if arr[-1] == brr[-1]:
    count += 1

print(count)

I’m not getting why the above solution is failing, please help me out. If possible give me a test case which may output wrong answer.

Last if condition is wrong,
Make loop from 1 to n Or from index 1 to n-1

1 Like

value inside bo is not changing for all index, print it for some input and see yourself.

I misunderstood the last condition and thought that we are not going to discard last question even if n - 1 was wrong.

okk, i missunderstood