AlgoMaster Logo

Expense Rule Engine: Solution Walkthrough

Medium Priority18 min readUpdated November 11, 2026

Expense Rule Engine is a small library that checks a batch of expenses against a company's spending rules. Rules are written as plain text, such as R1: category == meals and amount > 75. Each expense is a line of comma-separated text, and check() returns a Violation for every rule an expense breaks.

The round has four phases:

  • Phase 0: Read the existing code and fill in three blanks.
  • Phase 1: Fix a bug report: a rule for "anything over $20" flags a $9 lunch and lets a $150 dinner through.
  • Phase 2: Add two text operators, rules that cover a whole trip, and a way to register new operators and aggregates.
  • Phase 3: Grow the rule set to 50,000 rules and the batch to 300,000 expenses.

Most of the difficulty is in edge cases that an assistant will skip unless you name them. Amounts must be exact, a trip with nothing to count still gets checked, a resubmitted expense keeps its original place, and results follow rule order even after you index the rules.

Each of these has its own hidden test, and most have a plausible but wrong version built to fail it.

Premium Content

Subscribe to unlock full access to this content and more premium articles.