-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nolan Emirot
authored
Mar 18, 2019
1 parent
31ea62b
commit 6756be4
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
algo/cracking_coding_interview/minimumAbsoluteDifference.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |