-
Notifications
You must be signed in to change notification settings - Fork 353
/
Copy pathMaximum_Difference.py
50 lines (38 loc) · 1.15 KB
/
Maximum_Difference.py
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
50
'''
From all the positive integers entered in a list, the aim of the program is
to subtract any two integers such that the result/output is the maximum
possible difference.
'''
# class to compute the difference
class Difference:
def __init__(self, a):
# getting all elements from the entered list
self.__elements = a
def computeDifference(self):
# maximum difference would be the difference between the largest and the smallest integer
Difference.maximumDifference = max(self.__elements)-min(self.__elements)
return Difference.maximumDifference
# end of Difference class
# getting the input
_ = input()
a = [int(e) for e in input().split(' ')]
# creating an object of the class
d = Difference(a)
# calling function 'computeDifference' to compute the difference
d.computeDifference()
# printing the result
print(d.maximumDifference)
'''
COMPLEXITY:
Time Complexity -> O(N)
Space Complexity -> O(1)
Sample Input:
3
1 2 5
Sample Output:
4
Explanation:
Integer with max value--> 5
Integer with min value--> 1
Hence, maximum difference--> 5-1 = 4
'''