Skip to content

Commit

Permalink
Create minimumAbsoluteDifference.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Nolan Emirot committed Mar 18, 2019
1 parent 31ea62b commit 6756be4
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions algo/cracking_coding_interview/minimumAbsoluteDifference.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/python

import math
import os
import random
import re
import sys

# Complete the minimumAbsoluteDifference function below.
def minimumAbsoluteDifference(arr):
a = sorted(arr)
m = float('inf')
for i in range(1, len(a)):
dif = abs(a[i] - a[i-1])
m = min(m,dif )
return m

if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')

n = int(raw_input())

arr = map(int, raw_input().rstrip().split())

result = minimumAbsoluteDifference(arr)

fptr.write(str(result) + '\n')

fptr.close()

0 comments on commit 6756be4

Please sign in to comment.