My issue
i am getting wrong answer for this code
t = int(input())
for _ in range(t):
n=int(input())
a=list(map(int,input().split()))
a.sort()
if n%2 == 0:
count = n//2
else:
count = n//2 + 1
i = n//2
while i >0:
if a[i] == a[i-1]:
count = count + i
i = i - 1
else:
break
print(count) may i knoe the problem
My code
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
a.sort()
if n % 2 == 0:
count = n // 2
else:
count = n // 2 + 1
i = n // 2
duplicates = 0
while i > 0:
if a[i] == a[i - 1]:
count -= 1
i -= 1
else:
break
print(count)
Learning course: Kalasalingam Academy of Research and Education
Problem Link: CodeChef: Practical coding for everyone