#K33142. Maximum Average Temperature
Maximum Average Temperature
Maximum Average Temperature
You are given an array of integers representing the temperatures over N days and an integer K. Your task is to find the subarray of K consecutive days that yields the highest average temperature.
The average temperature for a subarray is computed as:
$$\text{average} = \frac{\sum_{i=1}^{K} temperature_i}{K}$$
If the number of days is less than K, output 0.
Example:
Input: 6 4 1 12 -5 -6 50 3</p>Output: 12.75
Explaination: The subarray [12, -5, -6, 50] has the maximum average (12.75).
inputFormat
The first line contains two integers N and K separated by a space, where N is the number of days and K is the number of consecutive days to consider. The second line contains N space-separated integers representing the temperature values.
outputFormat
Output a single floating point number representing the highest average temperature from any contiguous subarray of length K. If N < K, output 0.
## sample6 4
1 12 -5 -6 50 3
12.75