Parse and Evaluate Configurable Card Fee Rule Expressions

Last updated: November 29, 2026

Quick Overview

Program managers define fee rules as text such as `min(max(2.50, amount * 0.015), 25)`. Write a parser and evaluator that supports numbers, variables, + - * /, unary minus, parentheses and min/max with any number of arguments, using exact decimal arithmetic and rounding the result to cents.

SoFi
Coding & Algorithms
Software Engineer
SoFi
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


Program managers define fee rules as text such as `min(max(2.50, amount * 0.015), 25)`. Write a parser and evaluator that supports numbers, variables, + - * /, unary minus, parentheses and min/max with any number of arguments, using exact decimal arithmetic and rounding the result to cents.

Galileo lets its fintech clients configure card program behavior, and fee or reward rules expressed as small formulas are a natural fit for that kind of platform. This hard onsite question checks recursive descent parsing with correct precedence, decimal money arithmetic, and clear error handling for bad rules before they reach production.

What the Interviewer Expects
  • Writes a tokenizer and a grammar with correct precedence and associativity
  • Implements recursive descent that builds an AST once and evaluates it many times
  • Uses Decimal rather than float and rounds half up only at the end
  • Rejects malformed input and unknown functions with useful errors
  • Never uses Python eval on user-supplied text
Key Topics to Cover
recursive descent parsing
tokenization
abstract syntax trees
decimal arithmetic
configuration safety
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 comparison operators and an if(cond, a, b) function?
  • How would you validate a rule at save time so it cannot fail at transaction time?
  • How would you make evaluation fast for millions of transactions a day?
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 elements: numbers with optional decimals, identifiers bound to a variables dict, binary + - * /, unary minus, parentheses, and min/max calls with one or more arguments. Left associativity ...

High-Level Design

Parse once into a tuple-based AST at rule save time, then evaluate per transaction. The grammar gives precedence by layering: expr handles + and -, term handles * and /, unary handles negation, ...


Submit Your Answer
Markdown supported

Related Questions