Arithmetic expression evaluator
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) → intExamples
in
["a + b * 2",{"a":3,"b":4}]out11What 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
solution.py
InputExpectedGot
["a + b * 2",{"a":3,"b":4}]11not run yetsample