Evaluate Feature Flag Targeting Rules With Precedence and Parentheses

Last updated: November 29, 2026

Quick Overview

Write a parser and evaluator for targeting rules like `country IN ("DE", "AT") AND (plan == "pro" OR NOT beta) AND age >= 18`, supporting AND, OR, NOT, comparisons, IN lists and parentheses with correct precedence, evaluated against a user attribute map.

EPAM Systems
Coding & Algorithms
Software Engineer
EPAM Systems
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


Write a parser and evaluator for targeting rules like `country IN ("DE", "AT") AND (plan == "pro" OR NOT beta) AND age >= 18`, supporting AND, OR, NOT, comparisons, IN lists and parentheses with correct precedence, evaluated against a user attribute map.

Client platforms that EPAM builds often need configurable rollout or entitlement rules owned by business users rather than code. The question checks whether you can write a small recursive descent parser with correct precedence, separate parsing from evaluation, and produce helpful errors.

What the Interviewer Expects
  • Tokenize numbers, quoted strings, identifiers, operators and keywords
  • Encode precedence in the grammar: NOT over AND over OR
  • Parse once into an AST and evaluate many times per user
  • Define behavior for missing attributes and type mismatches
  • Raise clear syntax errors with position or token
Key Topics to Cover
recursive descent parsing
operator precedence
abstract syntax trees
tokenization
feature flags
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 prevent a rule from being too expensive, for example huge IN lists?
  • How would you add percentage rollout like `bucket(user_id) < 20` deterministically?
  • How would you validate rules at save time against a known attribute schema?
  • Would you ever use `eval` for this? Why not?
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

Grammar, lowest precedence first: or := and (OR and)*, and := not (AND not)*, not := NOT not | cmp, cmp := value (op value | IN '(' list ')')?, value := literal | identifier | '(' or ')'. Ke...

High-Level Design

A regex tokenizer, a recursive descent parser producing tuple AST nodes, and a tree-walking evaluator. Grammar layering gives precedence, so a OR b AND c parses as a OR (b AND c). Never eval use...


Submit Your Answer
Markdown supported

Related Questions