Best Contiguous Run of Daily Profit for a Cloud Customer
Last updated: November 29, 2026
Quick Overview
Given a list of a Google Cloud customer's daily net profit (positive or negative), return the maximum total profit over any non-empty run of consecutive days.
0
0
0 solved
Given a list of a Google Cloud customer's daily net profit (positive or negative), return the maximum total profit over any non-empty run of consecutive days.
A Google phone screen staple framed around finding a customer's best contiguous stretch for a case study in Cloud sales. The interviewer checks whether you derive Kadane's algorithm by reasoning about the best run ending at each day, and whether you handle the all-negative case.
What the Interviewer Expects
- Explains the brute force over all subarrays
- Derives Kadane's recurrence: best ending here = max(x, prev + x)
- Handles all-negative input by requiring a non-empty run
- Optionally returns the start and end days of the run
- States O(n) time, O(1) space
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Also return the start and end indices of the best run.
- What if the run may wrap around from the end of the year to the start?
- What if you must skip at most one day inside the run?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input: non-empty list of integers
profit. - Output: maximum sum of
profit[i..j]over0 <= i <= j < n, plus the indices as a bonus. - The run must contain at least one day, so if all days lose ...
High-Level Design
Let cur be the best sum of a run that ends exactly at the current day. Either the run starts fresh today (x) or it extends yesterday's best run (cur + x). Take the larger. The global answer is t...