blob: 2018d6496056d55903b8a58de79c25a71be5a8fd (
plain)
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
48
49
|
#!/usr/bin/env python3
#
#
# max-gap.py
#
# TASK #1 › Maximum Gap
# Submitted by: Mohammad S Anwar
# You are given an array of integers @N.
#
# Write a script to display the maximum difference between two successive
# elements once the array is sorted.
#
# If the array contains only 1 element then display 0.
#
# Example
#
# Input: @N = (2, 9, 3, 5)
# Output: 4
#
# Input: @N = (1, 3, 8, 2, 0)
# Output: 5
#
# Input: @N = (5)
# Output: 0
#
#
# © 2021 colin crain
## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
import sys
def gapIndexed( list ):
list = sorted(list)
i = 1
gap = 0
while i < len(list):
gap = max( gap, int(list[i]) - int(list[i-1]) )
i += 1
return gap
input = sys.argv[1:]
print( "input array: ", input )
gap = gapIndexed( input );
print( "maximum gap: ", gap )
|