IPv4 CIDR firewall allowlist
Implement an IPv4 firewall allowlist. Given a list of CIDR blocks (strings like '10.0.0.0/8' or a bare '192.168.1.5' meaning /32) and a candidate IPv4 address string, return True if the address falls inside ANY of the CIDR blocks. Parse dotted-quad addresses to 32-bit integers yourself; for a block a.b.c.d/n, the address matches if its top n bits equal the block's top n bits. A /0 block matches everything. You may use the ipaddress module is NOT required — implement the masking directly.
Implement
ip_allowed(cidrs: list[str], ip: str) → boolExamples
in
[["10.0.0.0/8","192.168.1.0/24"],"10.5.4.3"]outtrueWhat 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 25 min
solution.py
InputExpectedGot
[["10.0.0.0/8","192.168.1.0/24"],"10.5.4.3"]truenot run yetsample