Code Room
CodingMediumcod-g862
Subject Expression evaluationLevel Mid–Senior~30 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.