Track Downloaded Byte Ranges of a Large File with Range Queries

Last updated: November 29, 2026

Quick Overview

Implement a structure over half-open integer ranges supporting add(l, r) to mark bytes as downloaded, remove(l, r) to unmark them, and query(l, r) to check whether every byte in [l, r) is currently marked.

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

0

0

0 solved


Implement a structure over half-open integer ranges supporting add(l, r) to mark bytes as downloaded, remove(l, r) to unmark them, and query(l, r) to check whether every byte in [l, r) is currently marked.

Framed around resumable downloads in Chrome or Google Drive sync, this tests maintaining a sorted set of disjoint intervals under insert and delete. Interviewers look for correct merging and splitting with binary search and attention to half-open boundaries where most bugs live.

What the Interviewer Expects
  • Keeps a sorted list of disjoint, non-adjacent intervals
  • Uses binary search to find the affected span of intervals
  • Merges overlapping and touching intervals on add
  • Splits intervals partially covered by remove
  • Explains complexity and when a segment tree is preferable
Key Topics to Cover
Intervals
Binary Search
Sorted List
Segment Tree
Design
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 total number of bytes downloaded at any time in O(1).
  • Return the first missing byte at or after a position.
  • Ranges come from many concurrent download threads; how do you make it thread safe without a global lock?
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
  • Ranges are half-open [l, r) with l < r.
  • add unions the range in; remove subtracts it; query checks full coverage.
  • Many operations interleaved; the number of stored intervals can grow large...
High-Level Design

Store disjoint intervals sorted by start in spans, plus a parallel starts list for bisect (rebuilt after each mutation for clarity; a balanced tree or sortedcontainers would avoid that). add(l, r)...


Submit Your Answer
Markdown supported