Evaluate Reverse Polish Notation

Medium
StackMathAmazonLinkedIn
Evaluate an arithmetic expression given in Reverse Polish Notation. Valid operators are `+`, `-`, `*`, and `/`. Each operand is an integer. Division truncates toward zero. Input format: - First line: n - Second line: n space-separated tokens Print the integer result.

Constraints

1 <= n <= 10^5
The expression is valid.
Every intermediate value and the result fit in a signed 64-bit integer.
Division never uses a zero divisor.

Sample tests

Sample 1

Sample 2

Sign in to submit