Aggregate IPv4 Prefixes Into a Minimal Covering Set
Last updated: November 29, 2026
Quick Overview
Given a list of IPv4 prefixes that may overlap or be adjacent, return the smallest list of CIDR prefixes that covers exactly the same set of addresses, as a router would do for BGP route summarization.
Arista Networks
November 29, 20260
0
0 solved
Given a list of IPv4 prefixes that may overlap or be adjacent, return the smallest list of CIDR prefixes that covers exactly the same set of addresses, as a router would do for BGP route summarization.
Route summarization shrinks what a leaf advertises to the spine and what the FIB must hold in limited hardware tables. The interviewer checks whether you see the problem as interval merging plus aligned block decomposition and get the alignment bit math right.
What the Interviewer Expects
- Convert each prefix into an inclusive integer range
- Sort and merge overlapping and adjacent ranges
- Split each merged range into the largest aligned power-of-two blocks
- Use the lowest set bit (`s & -s`) to find alignment
- Prove the greedy split is minimal
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Why is the greedy largest-aligned-block split optimal?
- Summarize only prefixes that share the same next hop, and keep more specifics that differ.
- How would you allow a summary to cover a small amount of unused address space, and what are the risks (blackholing)?
- How would you update the aggregate incrementally as routes are withdrawn?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input prefixes may have host bits set; normalize them. Output: list of canonical prefixes, sorted, whose union equals the union of the input, with no smaller such list existing. 10.0.1.0/24 plus `10...
High-Level Design
Two steps. First, a prefix is just a range [start, start + 2^(32-len) - 1]; sort and merge ranges, joining adjacent ones (s <= prev_end + 1). Second, for each merged range, repeatedly emit the lar...