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
Coding & Algorithms
Software Engineer
ZipHQ
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

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
recursive descent parsing
operator precedence
abstract syntax tree
rule engines
error handling
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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 `('...


Submit Your Answer
Markdown supported

Related Questions