Question bank › Prefix Sum
Dsa Prefix Sum Medium

Max Incremental Gain in Segments

Given an array of integers that represent profits/losses over a series of days, write a program to find the maximum profit that can be earned by incrementally including days based on a starting index. You may skip days, but once you include a day in a segment, you must include all subsequent days until a total profit is calculated. Input format: - The first line contains an integer n (number of days). - The second line contains n space-separated integers, representing the profit/loss for each day. Output format: - Print the maximum profit obtainable from any starting day. Example: Input: 5 1 -2 3 -1 2 Output: 5

Key concepts

prefix_summax_subarraycumulative

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of Praxari's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.