Evaluate Feature Flag Rules With AND, OR, NOT and Parentheses

Last updated: November 29, 2026

Quick Overview

Given a rule string such as "beta AND (region_eu OR NOT legacy)" and a dictionary of flag values, parse and evaluate it with standard precedence (NOT, then AND, then OR).

IBM
Coding & Algorithms
Software Engineer
IBM
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Given a rule string such as "beta AND (region_eu OR NOT legacy)" and a dictionary of flag values, parse and evaluate it with standard precedence (NOT, then AND, then OR).

IBM products such as API Connect and watsonx Orchestrate evaluate policy and routing rules written as boolean expressions. This parsing question tests tokenization, a recursive descent grammar with correct precedence, and clear error handling instead of calling eval.

What the Interviewer Expects
  • Tokenize identifiers, keywords and parentheses
  • Write a grammar with one function per precedence level
  • Never use Python eval on user input
  • Raise clear errors on malformed rules and unknown flags
  • Discuss short-circuiting
Key Topics to Cover
recursive descent parsing
tokenization
operator precedence
expression evaluation
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 compile the rule once and evaluate it for millions of users?
  • How would you add comparison operators like plan == "enterprise"?
  • How would you report the column of a syntax error?
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

Keywords AND, OR, NOT are case-insensitive; identifiers are letters, digits and underscores. Unknown flags raise KeyError; malformed input raises ValueError. Precedence is NOT over AND over ...

High-Level Design

Grammar:

  • expr := term (OR term)*
  • term := factor (AND factor)*
  • factor := NOT factor | '(' expr ')' | IDENT

A regex tokenizer produces a list; a position index walks it. Each grammar rule ...


Submit Your Answer
Markdown supported

Related Questions