Reported July 2026
OpenAIbit manipulation

CIDR IPv4 Range Iterator

Reported by candidates from OpenAI's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live OpenAI OA. Under 2s to a working solution.
Founder's read

The edge case that kills the naive CIDR solution is /0, where the shift by 32 does something ugly, and OpenAI candidates reporting this one in July 2026 should expect it. You get a string like 192.168.1.5/30 and have to return every IPv4 address in that network, in order. It's a bit manipulation problem dressed up as string parsing. Parse four octets, pack them into a 32-bit value, mask, then walk start to end. If you blank on the mask math mid-assessment, StealthCoder runs invisibly on your desktop as a safety net, but the logic here is short enough to own tonight.

The problem

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.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick: pack the octets into one integer, build the mask as ((1 << 32) - 1) << (32 - prefix) & 0xFFFFFFFF, then start = ip & mask and end = start | (~mask & 0xFFFFFFFF). Loop from start to end inclusive and format each value back into dotted form with shifts and 0xFF. The pitfalls are all at the edges. Prefix 0 means a mask of zero and over four billion addresses, so say out loud that output size is 2^(32-prefix). Prefix 32 gives exactly one address. In languages with signed 32-bit ints, the high bit flips negative, so use 64-bit or unsigned shifts. Don't assume the input is already the network address, since the example 192.168.1.5/30 starts at.4. A generator or lazy iterator is the cleaner answer for huge ranges. If the live OA freezes you on shift widths, StealthCoder is the hedge that reads the screen and hands you the working version.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

If this hits your live OA

You can drill CIDR IPv4 Range Iterator cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as ip to cidr. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass OpenAI's OA.

OpenAI reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.

CIDR IPv4 Range Iterator FAQ

What's the core trick in the OpenAI CIDR iterator problem?+

Convert the address to a 32-bit integer, apply the prefix mask to get the network start, then OR with the inverted mask to get the end. After that it's a plain loop from start to end, converting each integer back to dotted notation with shifts and 0xFF.

How do I build the mask without overflow bugs?+

Use a 64-bit integer or unsigned type, then compute (0xFFFFFFFF << (32 - prefix)) & 0xFFFFFFFF. Handle prefix 0 separately, returning mask 0, because shifting by 32 is undefined or a no-op in many languages. This is the classic edge case.

What if the input IP isn't the network address?+

Mask it anyway. The example 192.168.1.5/30 returns addresses starting at 192.168.1.4, not.5. Always compute start as ip & mask rather than trusting the given host bits. Skipping that step is the most common wrong answer.

Should I worry about huge ranges like /0 or /8?+

Mention it. A /0 range is 2^32 addresses, so returning an array can blow memory. State the size formula 2^(32-prefix), then offer a lazy iterator or generator as the scalable option while still satisfying the String[] signature for normal cases.

How do I prep for this in 48 hours?+

Write the parse, mask, and format functions from scratch twice, then test prefixes 0, 1, 24, 30, and 32. Practice converting int to dotted string with shifts. That covers every branch this problem can throw at you, and it takes under an hour.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with OpenAI.

OA at OpenAI?
Invisible during screen share
Get it