Skip to content

Commit 6756be4

Browse files
author
Nolan Emirot
authored
Create minimumAbsoluteDifference.py
1 parent 31ea62b commit 6756be4

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/python
2+
3+
import math
4+
import os
5+
import random
6+
import re
7+
import sys
8+
9+
# Complete the minimumAbsoluteDifference function below.
10+
def minimumAbsoluteDifference(arr):
11+
a = sorted(arr)
12+
m = float('inf')
13+
for i in range(1, len(a)):
14+
dif = abs(a[i] - a[i-1])
15+
m = min(m,dif )
16+
return m
17+
18+
if __name__ == '__main__':
19+
fptr = open(os.environ['OUTPUT_PATH'], 'w')
20+
21+
n = int(raw_input())
22+
23+
arr = map(int, raw_input().rstrip().split())
24+
25+
result = minimumAbsoluteDifference(arr)
26+
27+
fptr.write(str(result) + '\n')
28+
29+
fptr.close()

0 commit comments

Comments
 (0)