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.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

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
Kadane's Algorithm
Dynamic Programming
Arrays
Maximum Subarray
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample Answer
Requirements
  • Input: non-empty list of integers profit.
  • Output: maximum sum of profit[i..j] over 0 <= 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...


Submit Your Answer
Markdown supported