Track Seen Video IDs in Compact Memory With a Bitset

Last updated: November 29, 2026

Quick Overview

A service must record which of up to 2 billion dense integer video IDs a batch job has processed; implement a bitset with set, test and count operations and compare its memory cost with a hash set.

Google
Software Engineering Fundamentals
Software Engineer
Google
November 29, 2026
Software Engineer
Phone Screen
Software Engineering Fundamentals
Easy

0

0

0 solved


A service must record which of up to 2 billion dense integer video IDs a batch job has processed; implement a bitset with set, test and count operations and compare its memory cost with a hash set.

YouTube-scale batch jobs often need membership over dense integer ID spaces, and a Python set or Java HashSet of billions of ints does not fit on a worker. The screen checks basic bit math and quick memory estimation.

What the Interviewer Expects
  • Map an id to a byte index and bit offset
  • Implement set, clear, test and population count
  • Estimate memory for bitset versus hash set
  • Validate the id range
  • Know when a bitset is the wrong tool
Key Topics to Cover
bitset
bit manipulation
memory estimation
membership
popcount
How to Approach This
  1. Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
  2. Choose data structures based on access patterns, not familiarity.
  3. Prefer immutable data and message passing over shared mutable state for concurrency.
  4. Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
  • What if IDs are sparse 64-bit values instead of dense?
  • How would you merge bitsets from 1000 workers?
  • When would you use a Bloom filter or Roaring bitmap instead?
  • How would you persist and memory map the bitset?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice System Design Problems
Sample Answer
Requirements
  • Bitset(n) supports ids in [0, n).
  • add(i), discard(i), contains(i), count(), and union(other).
  • Out-of-range ids raise IndexError....
High-Level Design

Id i lives in byte i >> 3 at bit i & 7. Setting is buf[i>>3] |= 1 << (i & 7), testing is an AND. For 2 billion ids that is 2e9 / 8 = 250 MB, which fits on any worker. A Java HashSet<Integer>...


Submit Your Answer
Markdown supported