Problem · String
CIDR IPv4 Range Iterator
Learn this problemProblem statement
You are given an IPv4 address in CIDR notation, such as 192.168.1.0/24. The prefix length fixes the leading bits of the 32-bit address; the remaining bits identify addresses inside the network.
Use the prefix mask to compute the inclusive network start and end addresses, then visit every IPv4 address in that range in increasing order.
Interview context
The third phone-screen part supplied a CIDR string and asked candidates to calculate its start and end addresses with bitwise operations, then iterate over the full network range.
Function
iterateCIDR(cidr: String) → String[]Examples
Example 1
cidr = "192.168.1.5/30"return = ["192.168.1.4", "192.168.1.5", "192.168.1.6", "192.168.1.7"]A /30 prefix leaves two host bits. Masking 192.168.1.5 gives network start 192.168.1.4 and network end 192.168.1.7.
More OpenAI problems
- Memory AllocatorPHONE SCREEN · Seen Jul 2026
- Message Event AggregationONSITE INTERVIEW · Seen Jul 2026
- Plant Infection Simulation, Part 4: Death CountdownPHONE SCREEN · Seen Jun 2026
- Streaming Entropy, Part 1: Batch EntropyONSITE INTERVIEW · Seen Jun 2026
- Streaming Entropy, Part 2: Numerically Stable EntropyONSITE INTERVIEW · Seen Jun 2026
- Streaming Entropy, Part 3: Block-wise EntropyONSITE INTERVIEW · Seen Jun 2026
- Streaming Entropy, Part 4: Stable Streaming EntropyONSITE INTERVIEW · Seen Jun 2026
- Resumable List IteratorPHONE SCREEN · Seen Jun 2026