Largest Product of a Contiguous Run of Growth Multipliers

Last updated: November 29, 2026

Quick Overview

Each week a metric changes by an integer multiplier that can be negative or zero after data corrections. Find the contiguous run of weeks whose multipliers have the largest product.

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

0

0

0 solved


Each week a metric changes by an integer multiplier that can be negative or zero after data corrections. Find the contiguous run of weeks whose multipliers have the largest product.

A Google phone screen problem that tests whether you can extend Kadane's idea when a negative factor flips the order. Interviewers look for tracking both the maximum and minimum product ending at each position.

What the Interviewer Expects
  • Explain why the max-only Kadane recurrence fails with negatives
  • Track both max and min products ending at each index
  • Handle zeros as resets naturally
  • Initialize with the first element, not 0 or 1
  • Discuss overflow in fixed-width languages
Key Topics to Cover
1D dynamic programming
Kadane variant
Max and min tracking
Sign handling
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
  • Return the start and end indices of the best run.
  • What if the values are floats between 0 and 2?
  • Solve it with prefix and suffix products instead.
  • How would you avoid overflow if values can be large?
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 m of integers. Output the maximum product over all non-empty contiguous subarrays. A single negative element on its own is a valid answer if nothing better exists....

High-Level Design

Let hi[i] and lo[i] be the largest and smallest product of a subarray ending at i. A new element x either starts fresh or extends the previous best or worst run: `hi[i] = max(x, x * hi[i-1], x * l...


Submit Your Answer
Markdown supported