62 / 75
M

Evaluate Reverse Polish Notation

#62
stackarraymath

Use stack: push numbers, pop two operands on operator, compute and push result.

Example:

Input:tokens=['2','1','+','3','*']
Output:9 ((2+1)*3)

Common Mistakes:

  • Wrong operand order (a = second pop, b = first pop, compute a op b)
  • Not handling negative numbers in input
  • Using switch without break statements
  • Forgetting division truncates toward zero

Notes:

Classic stack application. Time O(n), Space O(n). RPN avoids parentheses and operator precedence issues.

62/75
Evaluate Reverse Polish Notation