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
Software Engineering Fundamentals
Software Engineer
Amazon
November 29, 2026
Software Engineer
Online Assessment
Software Engineering Fundamentals
Easy

0

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
CIDR
IPv4 addressing
bit manipulation
interval merging
binary search
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
  • 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 Problems
Sample Answer
Requirements
  • Input: CIDR strings like 10.0.0.0/16 (host bits may be set, as in 172.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 nn bits: network address ip & mask and broadcast network | ~mask, where mask = (0xFFFFFFFF << (32 - n)) & 0xFFFFFFFF. So 10.0.0.0/16 is `[167772160, 16783769...


Submit Your Answer
Markdown supported