 # Penalty Shoot out 2 - contest 2 DSA

i Just wanna ask that in this question can the ans be odd !?
or ans needs to be even necessarily!?

2 Likes

Yes the answer can be odd and for the test case below the answer will be 5

Input:
1
4
01010110

Output:
5

Explanation: As after the 5th index ( 3rd time A shoot) the values of win of a = 0 and values of win of b = 3, so we can say that B will always win.

I have figure out my code with different test case but it is showing an error. so it will be great help if one will find defect in code.

``````# https://www.codechef.com/LRNDSA02/problems/PSHOT
def main():
# TODO: write code...
for T in range(int(input())):
N = 2*int(input()) - 1
S = input()
a,b = 0,0
for i in range(N+1):
if i%2 == 0 and S[i] == '1':
a+=1
if a <= (b + ((N-i)//2)+1) :
continue
else:
print(i)
break

else:
if S[i]=='1':
b+=1
if b <= (a + ((N-i)/2)+1) :
continue
else:
print(i)
break
if a == b:
print(N+1)
del S

if __name__ == '__main__':
main()``````

While submitting the code its giving wrong answer. Please anyone can tell me about missing test case since I have cross checked for lot of values.

``````def x(s):
a,b=0,0
for i in range(len(s)):
if(i%2==0):
if(s[i]=='1'):
a+=1
if(((((len(s)-1)-i)//2)+a) < b):
return i+1
if(i%2!=0):
if(s[i]=='1'):
b+=1
if(((((len(s)-1)-i)//2)+b) < a):
return i+1

return len(s)

for t in range(int(input())):
n=int(input())
s=input()
print(x(s))``````

Please either format your code or (better!) link to your submission - the forum software has mangled it and it won’t compile! Thanks!

Consider the test input:

``````1
3
111011
``````

Thanks 1 Like