Evaluate Reverse Polish Notation

easy
Unit 2 · Stacks & Dynamic Programming0/3 to milestone

Evaluate an expression in Reverse Polish Notation given as a list of tokens: numbers (possibly negative) and operators + - * /. Division truncates toward zero (so -7 / 2 is -3). Raise ValueError for malformed expressions (too few operands, or leftover values).

Also implement to_rpn(tokens): convert an infix token list with + - * / and parentheses to RPN using the shunting-yard algorithm (all operators left-associative, * / bind tighter).

#stacks#parsing2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Evaluate Reverse Polish Notation · TechGradify