https://github.com/timoanttila/findminmaxsums
Find the maximum and minimum possible sums
https://github.com/timoanttila/findminmaxsums
javascript javascript-example javascript-examples javascript-examples-beginners javascript-test javascript-testing javascript-tests
Last synced: 2 months ago
JSON representation
Find the maximum and minimum possible sums
- Host: GitHub
- URL: https://github.com/timoanttila/findminmaxsums
- Owner: timoanttila
- Created: 2024-01-20T10:40:04.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-01-20T11:38:43.000Z (over 1 year ago)
- Last Synced: 2025-01-20T09:47:17.655Z (4 months ago)
- Topics: javascript, javascript-example, javascript-examples, javascript-examples-beginners, javascript-test, javascript-testing, javascript-tests
- Language: JavaScript
- Homepage:
- Size: 1000 Bytes
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Find the maximum and minimum possible sums
You are given three arguments:
- `arr` = an `array` of numbers
- `n` = the size of the `array`
- `k` = number of reduced elementsThe 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.
## Example 1
Input:
- `n` = 5
- `arr` = 1 2 3 4 5
- `k` = 1Logic:
- 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## Example 2
Input:
- `n` = 3
- `arr` = 5 6 7
- `k` = 2Logic:
- Remove the two lowest numbers: 7
- Remove the two highest numbers: 5
- Output: 7 5