Not understanding why my code is failing

I was attempting “LOTTERYTICK” problem - Lottery Tickets Practice Coding Problem

My code is failing for 2nd test case. Not sure why.

I checked few submissions. It appears that my logic to the problem is correct. But, I am failing my 2nd test case.

  • Sort the tickets
  • If chef is the minimum, then add the floor division by 2 for difference between the chef and the next highest
  • Similar for max, floor division by 2 for difference between the chef and the next lowest + (1000000 - chef)
  • If neither, then add left possible + right possible wins

t = int(input())

def LotteryTickets(n, tickets) :
    
    if n == 1 :
        return 1000000
    else :
        chef = tickets[0]
        win = 1
    
        sortedTickets = sorted(tickets)
    
        if chef == sortedTickets[0] :
            rightDiff = sortedTickets[1] - chef
            win += int(rightDiff/2)
        
        elif chef == sortedTickets[-1] :
            leftDiff = chef - sortedTickets[-2] 
            win = win + int(leftDiff/2) + (1000000 - chef) 
    
        else :
            left = sortedTickets[sortedTickets.index(chef) - 1]
            right = sortedTickets[sortedTickets.index(chef) + 1]
            leftDiff = chef - left
            win += int(leftDiff/2)
            rightDiff = right - chef
            win += int(rightDiff/2)
        
        return win
    

for _ in range(t):
    n = int(input())
    tickets = list(map(int, input().split()))
    print(LotteryTickets(n,tickets))