Given a list of numbers and a window size K, calculate three values: the total of all numbers, the largest sum of K consecutive numbers, and the whole-number average of the list. Keep the numbers in their original order.
Input: One line: window width K, followed by the nonnegative numbers in the row. Values are separated by whitespace.
Output: Print total, largest window sum, and floor average, in that order, separated by single spaces.
Input:
2 120 180 90 210 150
Output:
750 360 150
Explanation: The five values total 750. Width-two sums are 300,270,300,360, so the maximum is 360. The average is 750 / 5 = 150.
Input:
4 50 60 70 80
Output:
260 260 65
Explanation: Width four covers the entire row, whose sum is 260. Its only window also sums to 260, and the average is 65.
Input:
1 45 310 85 120
Output:
560 310 140
Explanation: The total is 560. With width one, the largest window is the largest value, 310. The average is 560 / 4 = 140.
Input:
3 100 100 100 100 100
Output:
500 300 100
Explanation: Five values of 100 total 500. Every width-three window sums to 300, and the average is 100.
Input:
2 10 15 12 400 450
Output:
887 850 177
Explanation: The total is 887. The final pair 400 + 450 gives the maximum window sum 850. Floor 887 / 5 to get average 177.
When a window moves one position, which one value leaves and which one enters?
Level 5 applies the same sliding-window calculation to supplied timing samples. Its response also includes the sample count and field labels; neither exercise measures a real command's speed.
System 1: Build a Command-Line Shell
Optional application of the idea. You write the System solution separately.
Count repeated words and make their ranking predictable when counts tie.
750 360 150