Skip to the editor
JSGroundwork
JSGroundwork handwritten · web dev
←Back to Stacks & queues

Ready to read

JSJavaScript⑂Git◎Interview prepΣDSA in JSSDSystem Design
More topics15›
</>HTML{ }CSS⚛ReactNNext.jsNeNest.jsTSTypeScriptNoNode.js🐳DockerDBSQL & Databases✓Testing🔒Web Security☁Cloud & DevOps◈GraphQL◆Redis☸Kubernetes
☰‹›
Description
All topics›JavaScript›Stacks & queues

Evaluate Reverse Polish Notation

beginnerlayer B8 · Stacks & queues5 tests

Evaluate an arithmetic expression given in reverse Polish (postfix) notation. tokens is an array of strings: either an integer, or one of +, -, *, /.

  • An operator applies to the two values immediately before it, in order — so ['3','4','-'] is 3 - 4
  • Division is integer division that truncates toward zero: 7 / -3 is -2
  • The expression is always valid and never divides by zero

Stuck?

All exercisesPlayground
1234567891011121314
loading the editor…

Nothing yet — hit Run and whatever you log shows up here.

Submit to see how you did.

⌘/Ctrl + Enter run⌘/Ctrl + S save⌘/Ctrl + / comment⌘/Ctrl + F find/replace⌘/Ctrl + D select next matchAlt + click multi-cursorTab indent · ⇧Tab outdentEsc leave fullscreen