FastPrepSingle-Rule Ad Filter
Problems/Single-Rule Ad Filter

Single-Rule Ad Filter

The Walt Disney Company logoThe Walt Disney Company● EasyFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report asks for one ad-filter rule with optional locations and age bounds, AND/OR, and matching IDs in input order. It gives the A/B/C example. This practice makes location comparison case-insensitive, groups both inclusive age bounds as one criterion, treats missing criteria as inactive, and keeps all ads when neither is active. Parallel arrays and -1 for a missing bound are runner representations. About 85% of the reported task is represented; the added rules resolve omissions rather than recover original wording.

Filter a list of ads using one rule and return the matching IDs in their original input order. An ad has an ID, an integer viewer age and a set of target locations.

The parallel arrays ids, ages and adLocations describe the ads: row i is (ids[i], ages[i], adLocations[i]). The parameter mode carries the rule’s AND/OR operator. The rule has ruleLocations, minAge, maxAge and mode. For this exercise, -1 represents a missing age bound and an empty rule location list means no location criterion.

  • The age criterion is active if at least one bound is present. It passes only if the age satisfies every present bound, inclusively. The two bounds form one criterion even for OR.
  • The location criterion is active when ruleLocations is nonempty. It passes if the ad and rule share at least one location, ignoring ASCII letter case. An ad with no locations fails an active location criterion.
  • AND keeps an ad when every active criterion passes. OR keeps it when at least one active criterion passes. If neither criterion is active, keep every ad for either mode.

For this exercise, the model’s age field is used for both bounds; the source example’s minage label is treated as that same ad age. The grouping, case comparison, empty-criterion rules, parallel-array representation and bounds above are explicit practice choices.

Function

filterAds(ids: String[], ages: int[], adLocations: String[][], ruleLocations: String[], minAge: int, maxAge: int, mode: String) → String[]

Examples

Example 1

ids = ["A","B","C"]ages = [21,13,25]adLocations = [["US","CA"],["US"],["CA"]]ruleLocations = ["US"]minAge = 21maxAge = -1mode = "AND"return = ["A"]

A satisfies age at least 21 and shares US. B shares US but its age is too small. C satisfies the age bound but shares no rule location. AND therefore returns ["A"].

Example 2

ids = ["D","E","F"]ages = [25,20,35]adLocations = [["TX"],["ca"],["TX"]]ruleLocations = ["CA"]minAge = 30maxAge = -1mode = "OR"return = ["E","F"]

D fails both active criteria. E shares CA when case is ignored, and F satisfies the age bound. OR returns ["E","F"] in input order.

Constraints

  • 0 <= ids.length <= 2000. The three ad arrays have equal lengths.
  • IDs are distinct nonempty strings of at most 20 ASCII letters or digits.
  • 0 <= ages[i] <= 120
  • 0 <= adLocations[i].length <= 20 and 0 <= ruleLocations.length <= 20
  • Each location code has one to three ASCII letters. Location lists contain no case-insensitive duplicates.
  • -1 <= minAge <= 120 and -1 <= maxAge <= 120. When both are present, minAge <= maxAge.
  • mode is exactly AND or OR.

More The Walt Disney Company problems

  • Find All Paths for a Name in a File SystemPHONE SCREEN · Seen Nov 2026
  • Resizable Array-Backed Integer SetPHONE SCREEN · Seen Sep 2026
  • Shortest Path with Directional Move CostsPHONE SCREEN · Seen Sep 2026
All The Walt Disney Company interview questionsSee The Walt Disney Company hiring insights
Saved
class Solution {
    public String[] filterAds(String[] ids, int[] ages, String[][] adLocations, String[] ruleLocations, int minAge, int maxAge, String mode) {
        // Write your code here
    }
}
Checking account…