FastPrepIPv4 Reverse Iterator
Problems/IPv4 Reverse Iterator

IPv4 Reverse 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 decreasing numeric order until 0.0.0.0 is reached.

The starting address and 0.0.0.0 are both included. Decrementing an address borrows across octets, so the address before 10.0.1.0 is 10.0.0.255.

Interview context

The second part of the phone-screen prompt reversed the iterator: begin at the supplied IPv4 address, decrement one address at a time, and continue through 0.0.0.0. This function returns the exact finite sequence that iterator would yield.

Function

iterateIPv4Reverse(startIp: String) → String[]

Examples

Example 1

startIp = "0.0.0.2"return = ["0.0.0.2", "0.0.0.1", "0.0.0.0"]

The address decreases by one until the lower IPv4 bound is included.

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

}
Checking account…