Shortest Run of Hours Whose Net Follower Gain Reaches K
Last updated: November 29, 2026
Quick Overview
Given hourly net follower changes for a creator (values may be negative) and a target K, return the length of the shortest contiguous run of hours whose sum is at least K, or -1.
ByteDance
November 29, 20260
0
0 solved
Given hourly net follower changes for a creator (values may be negative) and a target K, return the length of the shortest contiguous run of hours whose sum is at least K, or -1.
Douyin creator analytics highlights the shortest window in which a creator gained a milestone number of followers. Because unfollows make values negative, the usual sliding window breaks, and the interviewer wants to see prefix sums with a monotonic deque and a clear explanation of why both pops are safe.
What the Interviewer Expects
- Explain why a two-pointer window fails with negatives
- Use prefix sums to turn the problem into pair search
- Maintain a deque of indexes with increasing prefix values
- Pop from the front when a valid window is found, and from the back when dominated
- Verify against a brute force on random inputs
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 hour too?
- What if you need the longest window with sum at most K?
- How would you answer this for many creators streaming in real time?
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 of integers (positive or negative) and K >= 1. Output: the minimum length of a non-empty subarray with sum >= K, or -1....
High-Level Design
Let P[j] be the prefix sum of the first j values. We want the smallest j - i with P[j] - P[i] >= K. Keep a deque of candidate start indexes with strictly increasing prefix values. For each j: wh...