FastPrepEvaluate Reverse Polish Notation

Evaluate Reverse Polish Notation

Coalition logoCoalition● MediumFULLTIMEPHONE SCREEN
Learn

Problem statement

Evaluate an arithmetic expression in Reverse Polish Notation. Each operator consumes the two preceding values, and integer division truncates toward zero.

Function

evalRPN(tokens: String[]) → int

Examples

Example 1

tokens = ["2","1","+","3","*"]return = 9

Add 2 and 1, then multiply the result by 3.

Constraints

  • 1 <= tokens.length <= 10000
  • Tokens are integers or one of +, -, *, /.
  • The expression is valid and no division uses zero.

More Coalition problems

See Coalition hiring insights
public int evalRPN(String[] tokens) {
  // Write your code here.
}
tokens["2","1","+","3","*"]
expected9
Checking account…