FastPrepCIDR IPv4 Range Iterator
Problems/CIDR IPv4 Range Iterator

CIDR IPv4 Range Iterator

OpenAI logoOpenAI● MediumFULLTIMEPHONE SCREEN
QuestionFunctionExamples

Problem 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

  • Determine the Winner of Three-Card HandsPHONE SCREEN · Seen Nov 2026
  • Sparse Plant Infection SimulationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Light Source Hits: Sample, Compare, and FitPHONE SCREEN · Seen Nov 2026
All OpenAI interview questionsSee OpenAI hiring insights
Saved
class Solution {
    public String[] iterateCIDR(String cidr) {
      // write your code here
    }

}
Checking account…