Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

Evaluate Reverse Polish Notation

Medium

Topics
ArrayStackMath

Evaluate an arithmetic expression in Reverse Polish Notation given as a list of tokens. Valid operators are + - * /; division truncates toward zero.

Example 1

Input:  tokens = ["2","1","+","3","*"]
Output: 9

Example 2

Input:  tokens = ["4","13","5","/","+"]
Output: 6

Constraints

  • 1 <= tokens.length <= 10^4
  • Tokens are integers or one of + - * /.
Run ⌘' · Submit ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access