Shortest Billing Period With Net Revenue At Least K Despite Refunds

Last updated: November 29, 2026

Quick Overview

Daily net revenue values can be negative because of refunds. Return the length of the shortest contiguous run of days whose total is at least k, or -1 if none exists.

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

0

0

0 solved


Daily net revenue values can be negative because of refunds. Return the length of the shortest contiguous run of days whose total is at least k, or -1 if none exists.

A Google onsite Hard follow-up to the positive-only window problem, framed around Google Play developer payouts with refunds. The interviewer checks that the candidate explains why the simple window breaks and switches to prefix sums with a monotonic deque.

What the Interviewer Expects
  • Explains why negatives break the two-pointer window
  • Builds prefix sums
  • Keeps a deque of indices with increasing prefix sums
  • Pops from the front when a valid window is found
  • States O(n) time
Key Topics to Cover
Prefix Sums
Monotonic Deque
Sliding Window
Negative Values
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 day of the period.
  • What if k can be negative or zero?
  • How would you answer for many k values at once?
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 rev of integers (may be negative), integer k >= 1.
  • Output: the minimum length of a contiguous block with sum >= k, or -1....
High-Level Design

With negatives, shrinking the left edge can increase the sum, so we cannot decide greedily when to shrink. Use prefix sums P[0] = 0, P[i+1] = P[i] + rev[i]. A block (i, j] works when `P[j] - P[i...


Submit Your Answer
Markdown supported