Evaluate Underwriting Rule Expressions Against an Applicant

Last updated: November 29, 2026

Quick Overview

Write an evaluator for rule strings such as `fico >= 640 AND (dti < 0.4 OR income > 80000)` against a dictionary of applicant attributes, supporting AND, OR, NOT, parentheses and the six comparison operators with standard precedence.

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

0

0

0 solved


Write an evaluator for rule strings such as `fico >= 640 AND (dti < 0.4 OR income > 80000)` against a dictionary of applicant attributes, supporting AND, OR, NOT, parentheses and the six comparison operators with standard precedence.

Upstart combines its ML scores with configurable eligibility and partner credit-box rules, and those rules are often stored as text that product and risk teams edit. Interviewers use this to see whether you can write a small tokenizer and a recursive descent parser with correct precedence, and report malformed input cleanly.

What the Interviewer Expects
  • Tokenize numbers, identifiers, operators and parentheses
  • Encode precedence NOT > AND > OR through grammar levels
  • Use recursive descent with a shared cursor
  • Raise clear errors on malformed rules
  • Never call eval on user-provided text
Key Topics to Cover
string parsing
recursive descent
tokenization
operator precedence
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
  • Compile the rule once and evaluate it for millions of applicants. What would you cache?
  • Add an IN operator, for example `state IN (CA, NY)`.
  • How would you explain which clause caused a decline?
  • How would you treat a missing attribute?
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

Operands are attribute names or numeric literals. Comparisons are binary. Logical precedence is NOT, then AND, then OR, and parentheses override it. Unknown attributes raise KeyError; malformed syntax...

High-Level Design

A regex tokenizer produces a list such as ['fico', '>=', '640', 'AND', '(', ...]. The grammar has one function per precedence level: or_expr := and_expr (OR and_expr)*, `and_expr := not_expr (AND ...


Submit Your Answer
Markdown supported

Related Questions