Parse and Evaluate Conditional Approval Rule Expressions
Last updated: November 29, 2026
Quick Overview
Admins write routing conditions like `amount >= 50000 AND (vendor.risk == 'high' OR NOT category == 'software')`. Write a tokenizer, a parser that respects NOT > AND > OR precedence, and an evaluator that runs a compiled rule against a request dictionary with nested fields.
ZipHQ
November 29, 20260
0
0 solved
Admins write routing conditions like `amount >= 50000 AND (vendor.risk == 'high' OR NOT category == 'software')`. Write a tokenizer, a parser that respects NOT > AND > OR precedence, and an evaluator that runs a compiled rule against a request dictionary with nested fields.
Zip lets each customer configure their own workflow branching conditions, so a rule language with clear semantics sits at the heart of the product. The onsite version probes recursive descent parsing, precedence, error reporting and how you define behavior for missing or mistyped fields.
What the Interviewer Expects
- Write a grammar before coding and map each level to a function
- Get precedence right: NOT binds tighter than AND, which binds tighter than OR
- Compile once to a tree, evaluate many times
- Raise clear errors on malformed input instead of crashing
- Define semantics for missing fields and type mismatches
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you add an `IN ('a', 'b')` operator?
- How would you statically validate a rule against a customer's field schema before saving it?
- How would you show an admin which clause made a rule evaluate to false?
- Would you store the expression string or the tree, and how would you migrate it?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Literals are numbers or single-quoted strings, fields may be dotted paths, comparisons are > < >= <= == !=, boolean operators are case-insensitive AND OR NOT with parentheses. A missing field make...
High-Level Design
Grammar: expr := term (OR term)*, term := factor (AND factor)*, factor := NOT factor | '(' expr ')' | FIELD OP LITERAL. A regex tokenizer produces typed tokens; the parser builds tuples like `('...