File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change
1
+ '''
2
+ From all the positive integers entered in a list, the aim of the program is
3
+ to subtract any two integers such that the result/output is the maximum
4
+ possible difference.
5
+
6
+ '''
7
+
8
+ # class to compute the difference
9
+ class Difference :
10
+ def __init__ (self , a ):
11
+ # getting all elements from the entered list
12
+ self .__elements = a
13
+ def computeDifference (self ):
14
+ # maximum difference would be the difference between the largest and the smallest integer
15
+ Difference .maximumDifference = max (self .__elements )- min (self .__elements )
16
+ return Difference .maximumDifference
17
+ # end of Difference class
18
+
19
+ # getting the input
20
+ _ = input ()
21
+ a = [int (e ) for e in input ().split (' ' )]
22
+
23
+ # creating an object of the class
24
+ d = Difference (a )
25
+ # calling function 'computeDifference' to compute the difference
26
+ d .computeDifference ()
27
+
28
+ # printing the result
29
+ print (d .maximumDifference )
30
+
31
+ '''
32
+
33
+ COMPLEXITY:
34
+
35
+ Time Complexity -> O(N)
36
+ Space Complexity -> O(1)
37
+
38
+ Sample Input:
39
+ 3
40
+ 1 2 5
41
+
42
+ Sample Output:
43
+ 4
44
+
45
+ Explanation:
46
+ Integer with max value--> 5
47
+ Integer with min value--> 1
48
+ Hence, maximum difference--> 5-1 = 4
49
+
50
+ '''
You can’t perform that action at this time.
0 commit comments