Check Whether Request IPs Fall Inside Allowed VPC CIDR Blocks
Last updated: November 29, 2026
Quick Overview
Given a list of allowed IPv4 CIDR blocks for a VPC, answer whether each incoming request's source address is inside any of them. Make lookups fast for thousands of blocks and explain how CIDR notation maps to integer ranges.
Amazon
November 29, 20260
0
0 solved
Given a list of allowed IPv4 CIDR blocks for a VPC, answer whether each incoming request's source address is inside any of them. Make lookups fast for thousands of blocks and explain how CIDR notation maps to integer ranges.
VPC security groups, network ACLs, and IAM source IP conditions all evaluate CIDR membership, so AWS engineers are expected to reason about addresses as integers. The interviewer checks bit-level understanding of prefixes and a sorted-interval lookup.
What the Interviewer Expects
- Converts dotted quads to 32-bit integers correctly
- Explains that a /n prefix fixes the top n bits, giving a range of $2^{32-n}$ addresses
- Merges overlapping and adjacent ranges
- Uses binary search for lookups
- Validates malformed input
Key Topics to Cover
How to Approach This
- Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
- Choose data structures based on access patterns, not familiarity.
- Prefer immutable data and message passing over shared mutable state for concurrency.
- Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
- How would you support IPv6 in the same structure?
- How would you find the most specific matching block, as a route table does?
- How would you handle frequent updates to the allowed list?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
- Input: CIDR strings like
10.0.0.0/16(host bits may be set, as in172.31.5.7/24). contains(ip)returns whether the address is in any block.- Many lookups per update....
High-Level Design
A block a.b.c.d/n keeps the top bits: network address ip & mask and broadcast network | ~mask, where mask = (0xFFFFFFFF << (32 - n)) & 0xFFFFFFFF. So 10.0.0.0/16 is `[167772160, 16783769...