-
Notifications
You must be signed in to change notification settings - Fork 1
/
s5.py
39 lines (27 loc) · 905 Bytes
/
s5.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
import sys
# Function to return the sum of
# the minimum pair from the array
def smallest_pair(a, n) :
min = sys.maxsize
secondMin = sys.maxsize
for j in range(n) :
# If found new minimum
if (a[j] < min) :
# Minimum now becomes
# second minimum
secondMin = min
#Update minimum
min = a[j]
# If current element is > min
# and < secondMin
elif ((a[j] < secondMin) and
a[j] != min) :
# Update secondMin
secondMin = a[j]
# Return the sum of the minimum pair
return (secondMin + min)
# Main func code
if __name__ == "__main__" :
arr = [ 1, 2, 3 ]
n = len(arr)
print(smallest_pair(arr, n))