Problem · String

IPv4 Reverse Iterator

Learn this problem
EasyOpenAIFULLTIMEPHONE SCREEN

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

drafts saved locally
public String[] iterateIPv4Reverse(String startIp) {
  // write your code here
}
startIp"0.0.0.2"
expected["0.0.0.2", "0.0.0.1", "0.0.0.0"]
checking account