FastPrepOrdered IP Firewall
Problems/Ordered IP Firewall

Ordered IP Firewall

Databricks logoDatabricks● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Databricks phone screen. The report defines ordered allow and deny rules over IPv4 addresses and CIDR networks, checking the first match, and a guaranteed match. It leaves out numeric limits. Our version is about 99% the same as the reported question.

You are given an ordered IPv4 firewall. Rule i has action actions[i], which is either "ALLOW" or "DENY", and target cidrs[i], which is either one IPv4 address or an IPv4 CIDR network.

Evaluate the query address against the rules in order. A plain address matches only itself. A CIDR target a.b.c.d/p matches exactly the addresses whose first p bits equal the target network's first p bits. Return true for the first matching ALLOW rule and false for the first matching DENY rule.

Function

allowAccess(actions: String[], cidrs: String[], ip: String) → boolean

Examples

Example 1

actions = ["DENY","ALLOW"]cidrs = ["10.0.0.0/8","0.0.0.0/0"]ip = "10.4.5.6"return = false

The address is inside 10.0.0.0/8, so the first rule matches and denies access.

Example 2

actions = ["ALLOW","DENY","ALLOW"]cidrs = ["192.168.1.9","192.168.1.0/24","0.0.0.0/0"]ip = "192.168.1.9"return = true

The exact-address rule appears before the broader deny rule, so its allow decision wins.

Constraints

  • 1 <= actions.length = cidrs.length <= 200000.
  • Every action is "ALLOW" or "DENY".
  • Every target and query is a valid dotted-decimal IPv4 address; a CIDR prefix is between 0 and 32.
  • At least one rule matches the query.

More Databricks Phone Screen questions

  • Rolling Hit CounterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Minimize CommuteOA · PHONE SCREEN · Seen Oct 2026
  • Top-K Values per Key in MapReducePHONE SCREEN · Seen Oct 2026
  • Customer Revenue with Direct ReferralsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • File Encryption Tree OptimizationPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Encrypted File Count and Minimum TimePHONE SCREEN · Seen Sep 2026
  • Circuit Breaker Database FailoverPHONE SCREEN · Seen Aug 2026
  • Find First Anagram IndexPHONE SCREEN · Seen Aug 2026
  • Key-Value Store GET and PUT QPSPHONE SCREEN · Seen Aug 2026
  • Snapshot Set IteratorPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026

Similar questions at other companies

  • Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
  • Elevator Scheduling SimulationOpenAI · PHONE SCREENOpenAI interview questions
  • Compress Editor Actions into Operational Transform OperationsReplit · OA · PHONE SCREEN · ONSITE INTERVIEW
  • Load/Store Arithmetic InterpreterJane Street · PHONE SCREENJane Street interview questions
  • RNG-Based Tree Document CodecBaseten · PHONE SCREENBaseten interview questions
  • Parking Garage AllocatorAmazon · PHONE SCREEN
  • Variadic Function Library MatchesIBM · PHONE SCREENIBM interview questions
  • Project and Filter Structured RecordsStripe · PHONE SCREENStripe interview questions
  • Out-of-Order TLV File ReassemblyApplied Intuition · PHONE SCREENApplied Intuition interview questions
  • Add Signed Character ArraysByteDance · PHONE SCREENByteDance interview questions

Databricks interview experiences

  • Databricks Senior SWE Onsite AI Rounds: 1 Experience
All Databricks interview questionsSee Databricks hiring insights
Saved
class Solution {
    public boolean allowAccess(String[] actions, String[] cidrs, String ip) {
        // Write your code here.
    }
}
Checking account…