The coding interview focused on implementing a product filtering system in Java. The task involved filtering a list of products based on optional category and price conditions, with support for both AND and OR operators.
The main challenge was handling optional filtering criteria correctly, especially when some fields were missing. The problem also required case-insensitive category matching, preserving the original product order, and reasoning about edge cases involving empty rules and partially matching products.
Interview Details
Coding — Single-Condition Product Filter
Problem Description
Given a list of products and a single filtering rule, implement a function that returns the IDs of all products satisfying the rule. Each product contains an ID, a set of category tags, and a price. The filtering rule can specify category tags, a minimum price, a maximum price, and a logical operator. The output must preserve the relative order of matching products from the original input list.
Data Model
The product and filtering rule have the following structures:
A product satisfies the category condition if at least one of its category tags overlaps with a tag specified in the filtering rule. Category matching is case-insensitive, so "AUDIO", "Audio", and "audio" must be treated as equivalent.
Price Matching
The rule may specify a minimum price, a maximum price, or both. The product's price must satisfy the active price bounds. For example, a rule with both a minimum and maximum price defines a permitted price range.
AND / OR Operators
The rule combines its applicable category and price criteria using the specified logical operator.
AND: The product must satisfy every applicable criterion.
OR: The product must satisfy at least one applicable criterion.
The important edge case is how optional conditions are handled. A missing category or price criterion should not accidentally make every OR rule match or every AND rule fail.