Trains the technique from
LeetCode 150Evaluate Reverse Polish NotationThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A machinist's paper-tape calculator writes its keystrokes in postfix order: values are typed first, and an operator key is pressed only once both values it will work on already sit on the tape. The finished tape arrives as tokens, one keystroke per entry. An entry is either a whole number in decimal, possibly carrying a minus sign, or one of the four keys "+", "-", "*", "/".
Replay the tape and report the single value that remains when the last keystroke has been handled.
Example 1
The minus key takes 5 as its left operand and 2 as its right, leaving 3 on the tape.
Example 2
A true quotient of -3.5 is pulled toward zero, so the tape keeps -3 rather than -4.
Example 3
The tape builds 11, doubles it to 22, then subtracts 5.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def eval_r_p_n(tokens: list[str]) -> int:public int evalRPN(String[] tokens)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.