Question: Given an array a of n numbers, consider the problem of computing the average of the first i numbers, for i ranging from 0 to

 Given an array a of n numbers, consider the problem of

Given an array a of n numbers, consider the problem of computing the average of the first i numbers, for i ranging from 0 to n - 1. That is, compute the array b of length n, where bi] Let us assume that all numbers are integer, and so averages are computed with no fractional part; for example. (2+5+1)/3 2. We call b the array of prefix averages of a. Write a program to compute the maximum of the prefix averages of a set of input numbers. Call your program MaxPrefixAverage. The input consists of two lines. The first line contains a single positive integer n, and the second line contains n integers separated by spaces single integer. . The output is a Your program should use O(1) memory; in particular, it may not use an array of length proportional to n. For example, if the input is 3 17 4 6 then the correct output is 4 This is because the prefix averages are: 3/1 3, (3 + 1)/2-2, (3 + 1 + 7)/3 = 3, (3+1+7+4)/4-3, and (3+1+7+4+6)/5 - 4. The maximum of these numbers is

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!