Code RoomArithmetic expression evaluator
MediumPrep Room Coding #1425

Arithmetic expression evaluator

CodingAlgorithms & data structuresMid–Senior~30 min

Evaluate an integer arithmetic expression string containing non-negative integers, single- or multi-letter variable names, the operators `+ - * /`, parentheses, and arbitrary spaces. A dict maps each variable name to an integer value. Standard precedence applies (`* /` before `+ -`), `/` is integer division truncated toward zero, and the input is well-formed. Return the integer result.

Implement
eval_with_vars(expr: str, varmap: dict) → int
Examples
in["a + b * 2",{"a":3,"b":4}]out11
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 30 min
InputExpectedGot
["a + b * 2",{"a":3,"b":4}]11not run yetsample