Count Request Bursts Whose Total Times Length Stays Below a Cost Cap

Last updated: November 29, 2026

Quick Overview

The cost of a contiguous burst of positive request weights is its sum multiplied by its length. Given the weights and a cap, count the non-empty bursts whose cost is strictly less than the cap.

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

0

0

0 solved


The cost of a contiguous burst of positive request weights is its sum multiplied by its length. Given the weights and a cap, count the non-empty bursts whose cost is strictly less than the cap.

A Google onsite Hard counting problem framed around a quota system that charges more for long, heavy bursts. The interviewer checks that the candidate proves the cost is monotone in window extension and then uses the count-per-right-edge sliding window.

What the Interviewer Expects
  • Shows the cost only grows when a window is extended
  • Keeps a running sum for O(1) cost evaluation
  • Shrinks left while the cost reaches the cap
  • Adds `right - left + 1` per right edge
  • Notes 64-bit overflow risks in other languages
Key Topics to Cover
Sliding Window
Counting Subarrays
Monotonicity
Running Sum
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
  • What if weights can be zero or negative?
  • Count bursts whose cost falls in a range [a, b).
  • What if the cost is sum times length squared?
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 w of positive integers, integer cap.
  • Cost of w[i..j] is sum(w[i..j]) * (j - i + 1).
  • Output: number of (i, j) with cost < cap....
High-Level Design

Monotonicity is the whole problem. Extending a window by a positive weight increases both the sum and the length, so the cost strictly increases; shrinking from the left decreases both. Therefore for ...


Submit Your Answer
Markdown supported