Merge IPv4 address ranges
Given a list of inclusive IPv4 address ranges as [start_ip, end_ip] pairs (each start <= end), merge all overlapping AND adjacent ranges (two ranges touch if one's start is exactly one greater than the other's end). Return the merged ranges sorted ascending as [start_ip, end_ip] string pairs. This is a different problem from generic interval merging because adjacency on the integer address space must coalesce. All IPs are valid IPv4.
Implement
merge_ip_ranges(ranges: list[list[str]]) → list[list[str]]Examples
in
[[["10.0.0.0","10.0.0.5"],["10.0.0.3","10.0.0.9"]]]out[["10.0.0.0","10.0.0.9"]]What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 22 min
solution.py
InputExpectedGot
[[["10.0.0.0","10.0.0.5"],["10.0.0.3","10.0.0.9"]]][["10.0.0.0","10.0.0.9"]]not run yetsample