-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMiniMaxSum.py
38 lines (30 loc) · 932 Bytes
/
MiniMaxSum.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
# Given five positive integers, find the minimum and maximum
# values that can be calculated by summing exactly four of
# the five integers. Then print the respective minimum and
# maximum values as a single line of two space-separated long
# integers.
#
# For example, arr = [1,3,5,7,9]. Our minimum sum is 1+3+5+7=16
# and our maximum sum is 3+5+7+9=24. We would print
# 16 24
#
# Link: https://www.hackerrank.com/challenges/mini-max-sum/problem
#!/bin/python3
import math
import os
import random
import re
import sys
# Complete the miniMaxSum function below.
def miniMaxSum(arr):
min_value = math.inf
max_value = -math.inf
sum = 0
for number in arr:
sum += number
min_value = min(min_value, number)
max_value = max(max_value, number)
print(sum - max_value, sum - min_value)
if __name__ == '__main__':
arr = list(map(int, input().rstrip().split()))
miniMaxSum(arr)