Reported July 2026
OpenAIbit manipulation

Convert an IPv4 Range to Minimal CIDR Blocks

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 detail that trips people up in this OpenAI question is the first address in the example: 255.0.0.7 can't start anything bigger than a /32. OpenAI candidates reported this one in July 2026, and it's a bit-math problem dressed up as networking. You get a start IP and a count n, and you return the fewest CIDR blocks that cover exactly that range, in order. If you blank on the alignment logic, StealthCoder runs invisibly on your screen during the live OA and gives you a working solution as a safety net. Know the trick first, though, because it's short.

The problem

You are given a starting IPv4 address ip and a number of consecutive addresses n to cover. Return CIDR blocks that represent exactly this address range.
A CIDR block consists of an IPv4 address, a slash, and the number of fixed leading bits. For example, 192.168.0.0/20 fixes the first 20 bits of each represented address.
Treat each IPv4 address as a 32-bit unsigned integer. Return the smallest possible number of CIDR blocks, ordered from the beginning of the requested range to its end.

Function
ipToCIDR(ip: String, n: int) → String[]

Examples
Example 1
ip = "255.0.0.7"
n = 10
return = ["255.0.0.7/32", "255.0.0.8/29", "255.0.0.16/32"]
The first address is unaligned and forms a one-address block. The next eight addresses form 255.0.0.8/29, and the final address forms another one-address block.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Convert the IP to a 32-bit integer. Then loop while n > 0. At each step, the largest block you can start here is limited by the lowest set bit of the current address, which is x & -x. It's also limited by n, so shrink the block size until it's at most n. Emit the block with prefix length 32 minus log2(size), then add size to the address and subtract it from n. Greedy works because taking the biggest aligned block each time minimizes the count. The common pitfall is forgetting that an address of 0 has no lowest set bit, so cap the size at 2^32. Also watch integer overflow in languages with signed 32-bit ints, and remember to convert back to dotted format. If the bit tricks slip under pressure, StealthCoder is the hedge on the live OA.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill Convert an IPv4 Range to Minimal CIDR Blocks 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. If you're reading this with an OA window open, you're who this was built for.

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. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Convert an IPv4 Range to Minimal CIDR Blocks FAQ

What's the trick in the OpenAI CIDR range problem?+

Greedy with alignment. At each address, the biggest block you can use is the lowest set bit of the address, capped by how many addresses remain. Emit that block, advance the address, repeat. That gives the minimum count and the right order.

How hard is this problem really?+

Medium on paper, but it feels harder if bit manipulation is rusty. The loop is about ten lines. Most of the pain is converting between dotted IPs and integers and getting the prefix length right, so test those helpers first.

How do I compute the prefix length for a block?+

If the block holds 2^k addresses, the prefix length is 32 minus k. For the example, 8 addresses is 2^3, so the prefix is /29. A single address is 2^0, so /32. Track k as you shrink the block size.

What edge cases should I test?+

Start at 0.0.0.0 where the lowest set bit is zero, n equal to 1, ranges ending at 255.255.255.255, and an unaligned start like the 255.0.0.7 example. Also check that your integer type is unsigned or wide enough to avoid overflow.

Can I prepare for this in 48 hours?+

Yes. Practice x & -x and shifts for a bit, then write the IP to int and int to IP helpers from memory. Walk the 255.0.0.7 example by hand until the three blocks fall out. That covers nearly everything this question tests.

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