You are given three arguments:
arr= anarrayof numbersn= the size of thearrayk= number of reduced elements
The arguments are passed in the order: n, arr, k.
Your task is to write the function findMinMaxSums which computes the maximum and minimum possible sums of the elements in the array after having discarded exactly k elements. Return these numbers in an array: [max, min]. You should not use any sorting library functions.
Input:
n= 5arr= 1 2 3 4 5k= 1
Logic:
- Remove the lowest number.
- The maximum amount is: 2 + 3 + 4 + 5 = 14.
- Remove the highest number.
- The minimum amount is: 1 + 2 + 3 + 4 = 10.
- Output: 14 10
Input:
n= 3arr= 5 6 7k= 2
Logic:
- Remove the two lowest numbers: 7
- Remove the two highest numbers: 5
- Output: 7 5