|
| 1 | +# [Mini-Max Sum](https://www.hackerrank.com/challenges/mini-max-sum) |
| 2 | + |
| 3 | +Difficulty: #easy |
| 4 | +Category: #warmup |
| 5 | + |
| 6 | +Given five positive integers, find the minimum and maximum values |
| 7 | +that can be calculated by summing exactly four of the five integers. |
| 8 | +Then print the respective minimum and maximum values as a single line |
| 9 | +of two space-separated long integers. |
| 10 | + |
| 11 | +## Example |
| 12 | + |
| 13 | +$ arr = [1, 3, 5, 7, 9] $ |
| 14 | +The minimum sum is $ 1 + 3 + 5 + 7 = 16 $ and the maximum sum |
| 15 | +is $ 3 + 5 + 7 + 9 = 24 $. The function prints |
| 16 | + |
| 17 | +```text |
| 18 | +16 24 |
| 19 | +``` |
| 20 | + |
| 21 | +## Function Description |
| 22 | + |
| 23 | +Complete the miniMaxSum function in the editor below. |
| 24 | +miniMaxSum has the following parameter(s): |
| 25 | + |
| 26 | +- arr: an array of $ 5 $ integers |
| 27 | + |
| 28 | +## Print |
| 29 | + |
| 30 | +Print two space-separated integers on one line: the minimum sum and |
| 31 | +the maximum sum of 4 of 5 elements. |
| 32 | + |
| 33 | +## Input Format |
| 34 | + |
| 35 | +A single line of five space-separated integers. |
| 36 | + |
| 37 | +## Constraints |
| 38 | + |
| 39 | +$ 1 \leq arra[i] \leq 10^9 $ |
| 40 | + |
| 41 | +## Output Format |
| 42 | + |
| 43 | +Print two space-separated long integers denoting the respective minimum |
| 44 | +and maximum values that can be calculated by summing exactly four of the |
| 45 | +five integers. (The output can be greater than a 32 bit integer.) |
| 46 | + |
| 47 | +## Sample Input |
| 48 | + |
| 49 | +```text |
| 50 | +1 2 3 4 5 |
| 51 | +``` |
| 52 | + |
| 53 | +## Sample Output |
| 54 | + |
| 55 | +```text |
| 56 | +10 14 |
| 57 | +``` |
| 58 | + |
| 59 | +## Explanation |
| 60 | + |
| 61 | +The numbers are $ 1, 2, 3, 4, $ and $ 5 $. Calculate the following sums using |
| 62 | +four of the five integers: |
| 63 | + |
| 64 | +1. Sum everything except $ 1 $, the sum is $ 2 + 3 + 4 + 5 = 14 $. |
| 65 | +2. Sum everything except $ 2 $, the sum is $ 1 + 3 + 4 + 5 = 13 $. |
| 66 | +3. Sum everything except $ 3 $, the sum is $ 1 + 2 + 4 + 5 = 12 $. |
| 67 | +4. Sum everything except $ 4 $, the sum is $ 1 + 2 + 3 + 5 = 11 $. |
| 68 | +5. Sum everything except $ 5 $, the sum is $ 1 + 2 + 3 + 4 = 10 $. |
| 69 | + |
| 70 | +**Hints**: Beware of integer overflow! Use 64-bit Integer. |
0 commit comments