PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Disney

Filter ads by a single rule

Last updated: Jun 2, 2026

Quick Overview

This question evaluates understanding of rule-based filtering for a single-rule ad filter, including set containment for locations, numeric range checks for age, handling of optional constraints, and operator logic (AND/OR).

  • medium
  • Disney
  • Coding & Algorithms
  • Software Engineer

Filter ads by a single rule

Company: Disney

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

## Single-Rule Ad Filter ### Context When a user watches content, the system needs to filter an ad pool to find ads that match **one rule**. Implement a lightweight filter that supports a **single rule** with an **operator**. ### Data model **Ad** - `id: String` - `targetLocations: Set<String>` (e.g., `{ "CA", "TX" }`) - `age: int` (intended viewer age for the ad) **Rule** - `targetLocations: Set<String>` (optional) - `minAge: Integer` (optional) - `maxAge: Integer` (optional) - `operator: "AND" | "OR"` ### Matching semantics - **Location match**: if `rule.targetLocations` is present and non-empty, then an ad matches the location constraint if `rule.targetLocations ⊆ ad.targetLocations` (i.e., the ad targets *all* locations required by the rule). - **Age match**: - if `rule.minAge` is present, require `ad.age >= rule.minAge` - if `rule.maxAge` is present, require `ad.age <= rule.maxAge` - Combine the (present) constraints using `rule.operator`: - `AND`: ad must satisfy **all** present constraints - `OR`: ad must satisfy **at least one** present constraint - If a constraint is absent, ignore it. ### Input / Output - **Input**: `List<Ad> ads`, `Rule rule` - **Output**: `List<String>` of matching `ad.id` values, **preserving the original input order** ### Example Rule: `minAge = 21`, `targetLocations = {"US"}`, `operator = AND` Ads: - `A`: `age=21`, `targetLocations={"US","CA"}` → match - `B`: `age=13`, `targetLocations={"US"}` → no (age) - `C`: `age=25`, `targetLocations={"CA"}` → no (location) Output: `["A"]` ### Constraints (assume) - `ads.length` can be large; keep it efficient. - Location strings may vary in case; clarify/handle consistently (e.g., normalize to upper-case) if needed.

Quick Answer: This question evaluates understanding of rule-based filtering for a single-rule ad filter, including set containment for locations, numeric range checks for age, handling of optional constraints, and operator logic (AND/OR).

Related Interview Questions

  • Implement an LRU cache - Disney (medium)
  • Determine if chasing points will meet - Disney (medium)
  • Solve matrix add, frequency count, longest consecutive - Disney (Medium)
  • Solve grid shortest path with BFS - Disney (Medium)
  • Implement BFS shortest path in grid - Disney (Medium)
Disney logo
Disney
Jan 22, 2026, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
10
0
Loading...

Single-Rule Ad Filter

Context

When a user watches content, the system needs to filter an ad pool to find ads that match one rule. Implement a lightweight filter that supports a single rule with an operator.

Data model

Ad

  • id: String
  • targetLocations: Set<String> (e.g., { "CA", "TX" } )
  • age: int (intended viewer age for the ad)

Rule

  • targetLocations: Set<String> (optional)
  • minAge: Integer (optional)
  • maxAge: Integer (optional)
  • operator: "AND" | "OR"

Matching semantics

  • Location match : if rule.targetLocations is present and non-empty, then an ad matches the location constraint if rule.targetLocations ⊆ ad.targetLocations (i.e., the ad targets all locations required by the rule).
  • Age match :
    • if rule.minAge is present, require ad.age >= rule.minAge
    • if rule.maxAge is present, require ad.age <= rule.maxAge
  • Combine the (present) constraints using rule.operator :
    • AND : ad must satisfy all present constraints
    • OR : ad must satisfy at least one present constraint
  • If a constraint is absent, ignore it.

Input / Output

  • Input : List<Ad> ads , Rule rule
  • Output : List<String> of matching ad.id values, preserving the original input order

Example

Rule: minAge = 21, targetLocations = {"US"}, operator = AND

Ads:

  • A : age=21 , targetLocations={"US","CA"} → match
  • B : age=13 , targetLocations={"US"} → no (age)
  • C : age=25 , targetLocations={"CA"} → no (location)

Output: ["A"]

Constraints (assume)

  • ads.length can be large; keep it efficient.
  • Location strings may vary in case; clarify/handle consistently (e.g., normalize to upper-case) if needed.

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Disney•More Software Engineer•Disney Software Engineer•Disney Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.