From 6756be4238ddb6638c3abe2313bfc40d276bb7cf Mon Sep 17 00:00:00 2001 From: Nolan Emirot Date: Sun, 17 Mar 2019 20:07:28 -0700 Subject: [PATCH] Create minimumAbsoluteDifference.py --- .../minimumAbsoluteDifference.py | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 algo/cracking_coding_interview/minimumAbsoluteDifference.py diff --git a/algo/cracking_coding_interview/minimumAbsoluteDifference.py b/algo/cracking_coding_interview/minimumAbsoluteDifference.py new file mode 100644 index 0000000..4faaf12 --- /dev/null +++ b/algo/cracking_coding_interview/minimumAbsoluteDifference.py @@ -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()