-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathP02_HORSES.py
47 lines (44 loc) · 1.32 KB
/
P02_HORSES.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# There are N horses in the stable. The skill of the horse i is represented by an integer S[i].
# The Chef needs to pick 2 horses for the race such that the difference in their skills is minimum.
# This way, he would be able to host a very interesting race. Your task is to help him do this and
# report the minimum difference that is possible between 2 horses in the race.
#
# Input:
# First line of the input file contains a single integer T, the number of test cases.
# Every test case starts with a line containing the integer N.
# The next line contains N space separated integers where the i-th integer is S[i].
#
# Output:
# For each test case, output a single line containing the minimum difference that is possible.
#
# Constraints:
# 1 ≤ T ≤ 10
# 2 ≤ N ≤ 5000
# 1 ≤ S[i] ≤ 1000000000
#
# Example:
#
# Input:
# 1
# 5
# 4 9 1 32 13
#
# Output:
# 3
# MY SOLUTION:
testCase = int(input())
for i in range(0, testCase):
n = int(input())
userInput = input().split()
userInput = sorted([int(i) for i in userInput])
mdif = (userInput[1] - userInput[0]) # Check difference
for i in range(0, n-1):
dif = userInput[i+1] - userInput[i]
if dif < mdif:
mdif = dif
print(mdif)
# OUTPUT for above solution:
# 1
# 5
# 4 9 1 32 13
# 3