Skip to content

Commit ecac11e

Browse files
authored
Add files via upload
1 parent 82331a0 commit ecac11e

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

Arrays/Min_Max_Sum.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
'''
2+
Aim: Given five positive integers, find the minimum and maximum values that can be calculated by summing exactly four of the five integers.
3+
4+
Example:
5+
arr = [1,3,5,7,9]
6+
The minimum sum is 1+3+5+7 = 16 and the maximum sum is 3+5+7+9 = 24. So, the output will be:
7+
16 24
8+
9+
'''
10+
11+
def MMSum(a):
12+
# sorting the array so that it becomes easier to find the min and max set of values
13+
a.sort()
14+
minn=0
15+
maxx=0
16+
for i in range(0,4):
17+
# summing up all minimum values
18+
minn+=a[i]
19+
for i in range(1,5):
20+
# summing up all maximum values
21+
maxx+=a[i]
22+
print(minn,maxx)
23+
24+
# getting the input
25+
user_input = (input().strip().split())
26+
array = []
27+
for i in user_input:
28+
array.append(int(i))
29+
# calling the Min-Max-Sum function
30+
MMSum(array)
31+
32+
'''
33+
34+
COMPLEXITY:
35+
36+
Time Complexity -> O(N)
37+
Space Complexity -> O(N)
38+
39+
Sample Input:
40+
2 1 3 4 5
41+
42+
Sample Output:
43+
10 14
44+
45+
Explanation:
46+
Sorted array: [1,2,3,4,5]
47+
Min Sum: 1+2+3+4 = 10
48+
Max Sum: 2+3+4+5 = 14
49+
50+
'''

0 commit comments

Comments
 (0)