Arithmetic expression evaluator

Write codeMedium30 min

Your task

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.

Examples

eval_with_vars(expr: str, varmap: dict) -> int
Example 1
Inputeval_with_vars("a + b * 2", {"a": 3, "b": 4})
Output11