FastPrepIPv4 Forward Iterator
Problems/IPv4 Forward Iterator

IPv4 Forward Iterator

OpenAI logoOpenAI● EasyFULLTIMEPHONE SCREEN
QuestionFunctionExamples

Problem statement

You are given an IPv4 address as a dotted-decimal string. Starting at that address, visit every IPv4 address in increasing numeric order until 255.255.255.255 is reached.

The starting address and 255.255.255.255 are both included. Incrementing an address carries across octets, so the address after 10.0.0.255 is 10.0.1.0.

Interview context

The phone-screen version asked candidates to implement a Python IPV4Iterator with __init__, __iter__, and __next__. It began at the supplied address and yielded every address through the IPv4 upper bound. This function returns the exact finite sequence that iterator would yield.

Function

iterateIPv4Forward(startIp: String) → String[]

Examples

Example 1

startIp = "255.255.255.253"return = ["255.255.255.253", "255.255.255.254", "255.255.255.255"]

The final octet advances twice before the maximum IPv4 address is reached.

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[] iterateIPv4Forward(String startIp) {
      // write your code here
    }

}
Checking account…