[ OK ]80cef547-8839-406a-9cb4-2bfb2786f986 — full content available
[ INFO ]category: Coding difficulty: unknown freq: first seen: 2026-03-13
[UNKNOWN][CODING]High Frequency
$catproblem.md
In a Databricks technical interview, the "Firewall CIDR Rules" problem typically asks you to implement a rule-based IPv4 firewall engine. PracHub +1 40
Problem Statement
You are given an ordered list of rules, where each rule consists of an action (ALLOW or DENY) and a target (either a specific IPv4 address or a CIDR block). 01
Your goal is to implement a function—often called allowAccess(ip)—that determines if a given target IP should be allowed access. The primary constraint is that only the first matching rule applies; if an IP matches multiple rules, the outcome is determined by the one that appears earliest in the list. LeetCode +1 201
Depending on the role level (e.g., Senior vs. Junior), the interviewer may add these complexities:
Dynamic Updates: Design data structures to efficiently support addRule(rule) and removeRule(ruleId) while maintaining low-latency queries.
Matching Semantics: Support different resolution strategies, such as "Most-Specific-Wins" (longest prefix match) instead of "First-Match-By-Priority".
Range Queries: Determine if an entire CIDR block is fully allowed or denied by the current rule set.
Scalability: How to handle 10610 to the sixth power106 rules and 10510 to the fifth power105 queries per second using advanced structures like Interval Trees or Radix Tries. PracHub +2
Suggested Technical Approach
Integer Conversion: Convert all IPv4 strings into 32-bit integers to allow for constant-time bitwise comparisons.
Bitmasking: For CIDR blocks (e.g., /24), precompute a bitmask. A match occurs if (queryIP & mask) == (ruleIP & mask).
Linear Scan (Baseline): For a small number of rules, iterating through the list is 𝑂(𝑁) per query.
Would you like to see a Python implementation of this logic or an explanation of how to handle overlapping rules?