n=int(input())
for i in range(n):
index=int(input())
arr=[]
res=[]
for j in range(index):
num=input()
arr.append(int(num))
arr.sort()
for k in range(index-1):
res.append(arr[k+1]-arr[k])
print(min(res))
n=int(input())
for i in range(n):
index=int(input())
arr=[]
res=[]
for j in range(index):
num=input()
arr.append(int(num))
arr.sort()
for k in range(index-1):
res.append(arr[k+1]-arr[k])
print(min(res))
Well here in the loop while taking the array as input you are making a mistake. input() take a line as input (in string format) so you can’t change it into integer and append it. I will suggest you to use map here to take input.
here is the modified code
n=int(input())
for i in range(n):
index=int(input())
arr= list(map(int,input().split()))
res=[]
arr.sort()
for k in range(index-1):
res.append(arr[k+1]-arr[k])
print(min(res))
PS: try to format your code next time you ask a query.
thank you