Best Compounding Streak in Daily Price Change Multipliers
Last updated: November 29, 2026
Quick Overview
Given daily price change multipliers for a product (integers that can be negative or zero), return the largest product of any contiguous run of days.
Amazon
November 29, 20260
0
0 solved
Given daily price change multipliers for a product (integers that can be negative or zero), return the largest product of any contiguous run of days.
Pricing analysts at Amazon look at compounding effects over stretches of days. The interviewer is testing the maximum product subarray DP, specifically whether you track both the maximum and minimum products because a negative factor swaps them.
What the Interviewer Expects
- Explain why Kadane on the maximum alone fails
- Track the max and min product ending at each day
- Swap them when the factor is negative
- Reset naturally through max(f, hi * f) at zeros
- 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
- How would you return the start and end days of the best streak?
- What changes if multipliers are floats like 0.97 and 1.04?
- How would you avoid overflow on very long runs?
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. Output: the maximum product of a non-empty contiguous subarray....
High-Level Design
For sums, the best subarray ending at i depends only on the best ending at i-1. For products, a large negative times a negative becomes a large positive, so the smallest product ending at i-1 matters ...