Question
Implement a longest-prefix-match routing table lookup. Given a list of [cidr, next_hop] routes where cidr is an IPv4 prefix like '10.0.0.0/8', and a destination IPv4 address, return the next_hop of the most specific (longest prefix length) matching route. A route matches if (dest & mask) == (network & mask). If no route matches, return 'none'. A '/0' default route matches everything. All addresses are valid IPv4.
route_lookup(routes: list[list[str]], ip: str) → str[[["0.0.0.0/0","default"],["10.0.0.0/8","r1"],["10.1.0.0/16","r2"]],"10.1.2.3"]out"r2"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.
Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.