Problem · String
IPv4 Forward Iterator
Learn this problemProblem 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.