01 · Question
Given a list of unique IPv4 addresses, return the most common first octet. If several octets tie, return any of them.
Example:
- Input:
["203.0.113.10", "198.51.100.5", "192.0.2.5", "203.0.113.5"] - Output:
203
02 · Analysis
An IPv4 octet is an 8-bit number, so it has only 256 possible values. Store each count directly at its octet index in a 256-element array.
Processing the addresses takes time. The count array uses extra space, regardless of the number of addresses.