Medium · Stacks & Queues
Calculate Postfix
Given an array tokens that forms a valid postfix (Reverse Polish) expression, where each token is an integer (possibly negative) or one of the operators +, -, * and /, return the value of the expression, with division truncating toward zero.
Examples
Example 1
{
"tokens": ["2", "1", "+", "3", "*"]
}Output: = 9
Example 2
{
"tokens": ["4", "13", "5", "/", "+"]
}Output: = 6
Rebuild it in the studio
Core interview problems are free with a full runner and lessons; Pro opens the complete library.