Created
June 16, 2017 16:43
-
-
Save mllopart/5483cc9d969e5a7717d0c4b73eea76cf to your computer and use it in GitHub Desktop.
Mini-Max Sum Hackerrank
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/python3 | |
''' | |
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. | |
''' | |
import sys | |
arr = list(map(int, input().strip().split(' '))) | |
maxNum = 0 | |
minNum = 0 | |
first = True | |
for i in range(len(arr)): | |
pos = 0 | |
suma = 0 | |
for n in arr: | |
if pos != i: | |
suma += n | |
pos += 1 | |
if first: | |
maxNum = suma | |
minNum = suma | |
first = False | |
else: | |
if suma > maxNum: | |
maxNum = suma | |
if suma < minNum: | |
minNum = suma | |
print(str(minNum)+' '+str(maxNum)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment