CJCoding With Joseph
15free / daySign inCreate account

Return a Heap Array of Running Maximums

Write exactly this function:

int* runningMax(const int* values, int n);

It returns a NEW array of n ints in which element i is the largest value found in values[0] through values[i]. The function allocates that array and returns it; it must not print anything.

In main: read an integer n (at least 1), read n integers into a heap array you allocate with new int[n], call runningMax, print the result, and then delete[] BOTH arrays.

Print exactly two lines. For the input 5 then 3 1 7 4 9 the output is exactly what is shown in Expected Output.

Line 1 is the literal text Running max: followed by each element of the returned array, each one preceded by a single space. Line 2 is Final:  followed by the last element of that array.

Free the memory you allocate - this question checks for memory leaks.

Write everything yourself, including main.

Expected Output:

Running max: 3 3 7 7 9
Final: 9

= newline. The output ends with a newline — print one after the last line.

Hints4 available
Topics:
Pointers
📥 Auto-Input:
5\n3 1 7 4 9\n
This input is automatically fed to your program's stdin
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.