Databricks Coding Interview: Firewall Block Membership
Based on questions reported for Databricks interviews
The interviewer opens
Hi, and thanks for joining. Welcome to your interview for the software engineer role at Databricks. We'll work through a coding problem together, so please think out loud as you code, and you can pause any time with the Pause button at the top right of your screen.
The problem is about a firewall deciding whether an address belongs to a network block, which is the kind of access-control logic that matters when securing data platforms. It's in the Problem tab on the right, so please read it through, and ask me any questions before you start.
The problem
A firewall needs to tell whether an IPv4 address falls inside a CIDR block.
ip: a dotted IPv4 address, e.g. "192.168.1.77".cidr: a block "a.b.c.d/p" with 0 ≤ p ≤ 32; the bits of a.b.c.d after the first p are zero.
Return true if the first p bits of ip equal the first p bits of the block's address, otherwise false. A /0 block contains every address, and a /32 block contains exactly one. Inputs are always well-formed.
Example: ip = "192.168.1.77", cidr = "192.168.1.0/24" → true
Sizes: one address and one block per call.