Help me in solving EQUALELE problem

My issue

Not Being able to come with a Logic. Everyone else have used a logic that is being generated by an AI

My code

# cook your dish here
def check(x,l):
    count=0
    for i in range (l-1):
        if l>1:
         if x[i]!=x[i+1]:
             count=count+1
             x[i:i+2] = [x[i],x[i]]
         else: 
            continue
        else:
           return print("1")
    print(count)
            
t = int(input())
for _ in range(t):
    n = int(input())
    A = list(map(int, input().split()))
    x = list(set(A))
    l = len(x)
    check(x, l)

Learning course: Arrays, Strings & Sorting
Problem Link: Practice Problem in - CodeChef

@shreetej07
logic is count the maximum frequency element
and then subtract that count from n.
ex for [1,1,1,2,3,4]
the maximum freq is 3 which is for 1 .
so i’ll subtract 3 from n which is 6 to get the answer .
here 6-3=3 will be the correct answer.