Sum of Minimum Bitrate Over Every Contiguous Video Segment

Last updated: November 29, 2026

Quick Overview

Given per-second bitrates of a video, return the sum over all contiguous segments of the minimum bitrate in that segment, modulo 10^9 + 7.

Meta
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


Given per-second bitrates of a video, return the sum over all contiguous segments of the minimum bitrate in that segment, modulo 10^9 + 7.

A Meta onsite question that tests contribution counting, framed around estimating worst-case quality across every clip a viewer might scrub to in Reels. The interviewer wants you to avoid O(n^2) enumeration and to handle duplicate values without double counting.

What the Interviewer Expects
  • Reframe the sum as each element times the number of segments where it is the minimum
  • Compute previous-smaller and next-smaller boundaries with monotonic stacks
  • Break ties asymmetrically (strict on one side, non-strict on the other)
  • Apply the modulus correctly
  • State O(n) time and space
Key Topics to Cover
Monotonic stack
Contribution technique
Combinatorics
Modular arithmetic
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
  • Compute the sum of maximums instead.
  • Compute the sum of (max - min) over every segment.
  • How would you answer this for many range queries [l, r]?
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 b of positive integers, length up to 3 * 10^4 or larger. Output: the sum over all pairs i <= j of min(b[i..j]), modulo 10^9 + 7. There are about n^2 / 2 segments, so enumerating them...

High-Level Design

Flip the sum: each element b[i] contributes b[i] times the number of segments where it is the chosen minimum. If left[i] is the distance to the previous element strictly smaller and right[i] t...


Submit Your Answer
Markdown supported