My issue
my question is that when we can e=remove 2 elements at a time why remove 3 ones at a time rather than 2 because if we took 2 at a time the score will be more.
My code thats working because i kept “max(0,diff) // 3” here max(0,diff) is no of ones left
t=int(input())
for _ in range(t):
n=int(input())
l=list(map(int,input().split()))
minCount = min(l.count(0) , l.count(1))
diff = l.count(1) - l.count(0)
print(minCount + max(0,diff) // 3)
### My code that not working because i kept "max(0,diff) // 2" here max(0,diff) is no of ones left
t=int(input())
for _ in range(t):
n=int(input())
l=list(map(int,input().split()))
minCount = min(l.count(0) , l.count(1))
diff = l.count(1) - l.count(0)
print(minCount + max(0,diff) // 2)
please here me understand why we should take 3 instead of 2
Problem Link: https://www.codechef.com/problems/SUBARRAYREM