FreeCareerPath
Build the PrimitiveMedium

Evaluate Reverse Polish Notation

Write `eval_rpn(tokens)` evaluating a list of tokens in postfix notation. Tokens are integers as strings, or one of `+ - * /`. Division truncates toward zero. eval_rpn(["2", "1", "+", "3", "*"]) -> 9 eval_rpn(["4", "13", "5", "/", "+"]) -> 6 Two traps, both about order. The second value popped is the left operand, so `a - b` and `a / b` break if you swap them. And Python's `//` floors rather than truncating, so `-7 // 2` is `-4` where this problem wants `-3`.

What to expect: A timer starts when you begin. Edit the starter code, run it against the test suite as many times as you like, then finish when you're done. The reference solution and interviewer follow-up questions unlock only after you finish.

Log in to start this session

Timed sessions and your results for "Evaluate Reverse Polish Notation" are saved to your account — logging in takes a few seconds.

Evaluate Reverse Polish Notation — FreeCareerPath