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.
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
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
- 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 ProblemsSample Answer
Requirements
- Input: list
revof integers (may be negative), integerk >= 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...