Code RoomIPv4 CIDR firewall allowlist
MediumPrep Room Coding #283

IPv4 CIDR firewall allowlist

CodingSecurityNetworking & APIsMid–Senior~25 min

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) → bool
Examples
in[["10.0.0.0/8","192.168.1.0/24"],"10.5.4.3"]outtrue
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 25 min
InputExpectedGot
[["10.0.0.0/8","192.168.1.0/24"],"10.5.4.3"]truenot run yetsample