Pick Three Non-Overlapping K-Day Promo Windows With Maximum Traffic

Last updated: November 29, 2026

Quick Overview

Given daily search traffic for a product category, choose three non-overlapping windows of exactly k consecutive days to run promotions, maximizing total traffic covered. Return the starting days, lexicographically smallest on ties.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


Given daily search traffic for a product category, choose three non-overlapping windows of exactly k consecutive days to run promotions, maximizing total traffic covered. Return the starting days, lexicographically smallest on ties.

A Google onsite hard that combines window sums with left-best and right-best prefix DPs. Interviewers check the O(n) structure and the careful tie-breaking needed to return the smallest indices.

What the Interviewer Expects
  • Precompute all window sums with a sliding sum
  • Build left-best and right-best index arrays
  • Enumerate the middle window and combine in O(1)
  • Get lexicographic tie-breaking right in both arrays
  • Achieve O(n) time and space
Key Topics to Cover
1D dynamic programming
Prefix best arrays
Sliding window sums
Tie-breaking
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
  • Generalize to m windows.
  • Windows may have different lengths k1, k2, k3.
  • Require at least g days between promotions.
  • Return the max total only, with O(1) extra space for m = 2.
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: list t of non-negative integers and integer k with 3k <= len(t). Output the starting indices (a, b, c) with a + k <= b and b + k <= c maximizing the sum of the three windows. On ties, return ...

High-Level Design

Let w[i] be the sum of t[i..i+k-1]. Define left[i] as the index of the best window starting in 0..i, keeping the earliest on ties (update only on strictly greater). Define right[i] as the be...


Submit Your Answer
Markdown supported