EvalFrame Technical Mock Interviews & Coding Practice

Evaluate Reverse Polish Notation

Medium · Stack · Algorithm problem · all problems

You are given an array of strings `tokens` that represents an arithmetic expression in a Reverse Polish Notation. Evaluate the expression. Return an integer that represents the value of the expression. Note that: * The valid operators are `+`, `-`, `*`, and `/`. * Each operand may be an integer or another expression. * The division between two integers always truncates toward zero. **Examples:** ```typescript evalRPN(["2","1","+","3","*"]) // 9 ((2 + 1) * 3) evalRPN(["4","13","5","/","+"]) // 6 (4 + (13 / 5)) ```

Solve It in the BrowserPractice Explaining It Out Loud

Optimal Approach

  • Time complexity: O(n)
  • Space complexity: O(n)

Single scan of tokens with O(1) push and pop stack operations.

Follow-Up Questions Interviewers Ask About Evaluate Reverse Polish Notation

  • Why Math.trunc instead of Math.floor for integer division?
    Math.trunc truncates toward zero, matching standard integer division rules for negative numbers (e.g. -6 / 132 -> 0).

Practice the full problem with execution, tests, and AI code review in the interactive lab — then rehearse explaining your solution in a live voice mock interview.