T=int(input())
for _ in range(T):
n=int(input())
nos=list(map(int,input().split()))
llist=[]
llist1=[]
count=0
for i in range(len(nos)):
if nos[i]==0:
count+=1
else:
llist.append(count)
count=0
for j in llist:
if j>0:
llist1.append(j)
#print(llist1)
if len(llist1)==1:
if llist1[0]%2!=0:
print(“Yes”)
break
else:
print(“No”)
break
if 0 not in nos:
print(“No”)
if 1 not in nos:
if len(nos)%2==0:
print(“No”)
if len(nos)%2!=0:
print(“Yes”)
if len(llist1)>1:
llist1.sort()
k=max(llist1)
x=llist1[-2]
if x>=k//2:
print(“No”)
else:
print(“Yes”)
please you indentation for your code
This is your solution: CodeChef: Practical coding for everyone
T=int(input())
for _ in range(T):
//10-15 lines of logic
if len(llist1)==1:
if llist1[0]%2!=0:
print("Yes")
break
else:
print("No")
break
You have used a break
statement inside the if, do you know what really it does?
The break
statement terminates the loop containing it. Control of the program flows to the statement immediately after the body of the loop.
If the break
statement is inside a nested loop (loop inside another loop), the break
statement will terminate the innermost loop.
so it will come out of the for
loop and stop.
Check for sample input and output in the question, your code doesn’t even pass that. try modifying it, remove break
and use elif
.
yes I changed it and it worked. Thank you. But still I am getting partially correct answer. I just removed the break statements.
Maybe you are going wrong with your logic.
check it once. !!