Largest Guaranteed Traffic Block Under an Hourly Viewer Histogram

Last updated: November 29, 2026

Quick Overview

Given hourly minimum concurrent viewers for a region, find the contiguous range of hours that maximizes (number of hours) times (minimum viewers within the range), which capacity planners use as the largest reliably fillable block. Return the value and the range.

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

0

0

0 solved


Given hourly minimum concurrent viewers for a region, find the contiguous range of hours that maximizes (number of hours) times (minimum viewers within the range), which capacity planners use as the largest reliably fillable block. Return the value and the range.

This is the largest-rectangle-in-histogram problem dressed as TikTok ad inventory or CDN pre-warm planning, and it appears in onsites where interviewers want a hard monotonic stack problem. They look for the O(n) stack solution, a crisp explanation of what each pop computes, and a brute-force check.

What the Interviewer Expects
  • Reduces the business framing to largest rectangle in a histogram
  • Explains that each bar is the minimum of exactly one maximal range
  • Monotonic increasing stack with a sentinel to flush
  • Computes left boundary from the new stack top after popping
  • Validates against a brute force on random inputs
Key Topics to Cover
monotonic stack
largest rectangle in histogram
previous smaller element
brute-force validation
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
  • Extend this to a 2D grid of region by hour to find the largest block of 1s.
  • How would you return all ranges that tie for the maximum?
  • What if you want the best block of at least 3 hours?
  • Can you do it with two passes computing previous and next smaller elements instead?
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 of non-negative integers. Output: (area, start, end) with end exclusive, area = (end - start) * min(viewers[start:end]), maximized. Empty input gives 0....

High-Level Design

For each hour h, consider the widest range where h is the minimum: it extends left until the first smaller value and right until the first smaller value. The answer is the best of these n candidates, ...


Submit Your Answer
Markdown supported