Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Evaluate Reverse Polish Notation

XPChallenge Points: 20
levelLevel: Medium

You are given an array of strings tokens representing an arithmetic expression written in Postfix Notation (also known as Reverse Polish Notation).
Your task is to evaluate the expression and return its integer result.
Rules:
• The valid operators are: +, -, *, /
• Each operand is either an integer or another valid postfix expression.
• Division between two integers truncates toward zero (e.g., 8 / -3 = -2).
• No division by zero will occur.
• The input always represents a valid arithmetic expression.
• The final result and all intermediate results fit in a 32-bit signed integer.

Example 1:

Input: tokens = ["5", "3", "+", "2", "*"]

Output: 16

Example 2:

Input: tokens = ["8", "4", "/", "6", "+"]

Output: 8

Example 3:

Input: tokens = ["12", "3", "-", "2", "5", "*", "+"]

Output: 19

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result