I am not able to figure out as to why i am getting a wrong answer in this question, or more precisely not able to figure out any corner cases that i have probably missed or if my logic as a whole is in correct. Any kind of help would be much appreciated.

My code:

for i in range(int(input())):

n=int(input())

l=list(map(int,input().split()))

s = ‘’.join(map(str, l))

l1=sorted(l)

maxx=l1[len(l1)-1]

s1=s.split(str(maxx))

if len(s1[0])+len(s1[len(s1)-1])>=n//2:

x=n-len(s1[0])-len(s1[len(s1)-1])

print(n//2-x+1)

else:

print(0)