Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started