Longest Stable Bitrate Stretch Where Fluctuation Stays Within a Limit

Last updated: November 29, 2026

Quick Overview

Given per-second bitrate samples from a Douyin live stream and an integer limit, return the length of the longest contiguous stretch where the maximum minus the minimum bitrate is at most limit.

ByteDance
Coding & Algorithms
Software Engineer
ByteDance
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Given per-second bitrate samples from a Douyin live stream and an integer limit, return the length of the longest contiguous stretch where the maximum minus the minimum bitrate is at most limit.

ByteDance's live streaming quality team cares about stable bitrate segments when tuning adaptive encoders, and this question is in the style of their technical screens. The interviewer is checking whether you can combine a sliding window with two monotonic deques instead of recomputing max and min per window.

What the Interviewer Expects
  • Identify a variable-size sliding window with a shrink condition
  • Maintain window max and min with two monotonic deques
  • Explain why each index enters and leaves each deque once
  • Achieve O(n) time
  • Handle empty input and limit = 0
Key Topics to Cover
sliding window
monotonic deque
two pointers
streaming metrics
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 seconds of the stretch.
  • What if you need the count of all valid subarrays instead of the longest?
  • How would you handle samples arriving as an unbounded stream?
  • Could a sorted multiset replace the deques, and at what cost?
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: a list of non-negative integers (kbps per second) and limit >= 0. Output: the maximum length of a contiguous window whose max minus min is at most limit, or 0 for empty input. Expect n up to ab...

High-Level Design

Use two pointers left and right. As right advances, push it into a decreasing deque (front is the window max) and an increasing deque (front is the window min). If max minus min exceeds limit, advance...


Submit Your Answer
Markdown supported