Arrays and linear scans
Accumulators, indices, and loop invariants
A monitoring job receives request counts in minute order. The report needs the total traffic and the first minute with the highest count. Sorting the readings would do extra work and make the original positions harder to track; storing the whole stream isn't necessary either.
If the busiest value appears again later, the report should still point to its first occurrence. That small requirement decides which comparison belongs in the loop.
Keeping the first busiest minute
Keep the running total and a candidate peak position. Replace the position only for a strictly larger reading; an equal later peak keeps the earlier position. The first reading establishes a candidate, while an empty input never does. This distinguishes an empty report from a real zero-traffic minute.
Summarising the stream once
For readings [6, 2, 6], the total moves through 6, 8, and 14. The busiest position stays at 0: the last reading ties rather than improves the peak. After every step, the retained information describes exactly the prefix already consumed. An empty stream has a total of zero and no busiest position; zero traffic is a real reading, not a missing value.
std::vector<Int> readings{8, 2, 8};
auto first = std::max_element(readings.begin(), readings.end());
// first - readings.begin() is 0; replacing on >= would select 2.When another pass costs more
Separate accumulation and maximum searches still cost O(n). Combining them reduces traversals and requires constant extra state. Use a signed wide accumulator: an int total can overflow even when every individual element fits in int. Signed overflow is undefined behavior. Do not sort just to extract a maximum: sorting changes the meaning of its index and costs O(n log n).
A scan takes O(n) arithmetic operations and a fixed number of summary values. Separate total, maximum, and first-position scans are also O(n); combining them saves traversals and supports a one-pass input. Sorting first adds O(n log n) work without improving this report.
Use the supplied Int, Vec, and Opt aliases. Numeric arithmetic fits signed long long; absence uses std::nullopt, and documented invalid inputs throw std::invalid_argument. Keep caller-owned containers unchanged.
The monitoring job can emit its total and peak position as soon as the final reading arrives.
Practice Arrays and linear scans
Implement the exercise in a full-screen workspace, then run its tests.