Skip to content

Connection and Device States

Your first input is a list of connections. Each connection is pair of devices, where each device is represented by it's IPV4 address. Each distinct device (IP address) may be in one of two states: active or inactive. All devices being inactive.

connections = [["192.168.0.0", "192.168.0.1"], ["192.168.0.2", "192.168.0.0"], ["192.168.0.0", "192.168.0.3"]]

Each connection can also be in one of two states: active or inactive. A connection is active only when both of it's devices are active. Since all devices begin inactive, all connections also begin inactive.

Your second input is a sequence of single IP addresses that is used to toggle device states, and therefore also connection states, in order.

toggleIps = ["192.168.0.1", "192.168.0.0", "192.168.0.2", "192.168.0.0", "0.0.0.0"]

For each IP in toggleIps, toggle the state of any matching devices and connections. After each toggle, calculate the "impact count": the number of connections which the device participates in and have changed from active to inactive, or inactive to active.

Return and array, where each element contains the impact count after the corresponding toggle. This gives us a timeline of connection/disconnection impact throughout the simulation.

Example: For connections = [["192.168.0.0", "192.168.0.1"], ["192.168.0.2", "192.168.0.0"], ["192.168.0.0", "192.168.0.3"]] and toggleIps = ["192.168.0.1", "192.168.0.0", "192.168.0.2", "192.168.0.0", "0.0.0.0"] the output should be numberOfDevices(connections, toggleIps) = [0, 1, 1, 2, 0]