Evaluate an Arithmetic Expression in Postfix Notation
Company: Amazon
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Onsite
Quick Answer: Practice a Amazon coding interview problem focused on evaluate an arithmetic expression in postfix notation. The prompt emphasizes edge cases, clean implementation, and verifiable test behavior without revealing the solution.
Examples
Input: {"tokens":["2","3","+","4","*"]}
Expected Output: 20
Explanation: (2+3)*4.
Input: {"tokens":["4","13","5","/","+"]}
Expected Output: 6
Explanation: 13/5 truncates to 2.
Input: {"tokens":["-7","3","/"]}
Expected Output: -2
Explanation: Truncate toward zero.
Input: {"tokens":["7","-3","/"]}
Expected Output: -2
Explanation: Negative divisor.
Input: {"tokens":["5"]}
Expected Output: 5
Explanation: Single value.
Input: {"tokens":["10","6","9","3","+","-11","*","/","*","17","+","5","+"]}
Expected Output: 22
Explanation: Complex expression.
Input: {"tokens":["3","4","-"]}
Expected Output: -1
Explanation: Subtraction order.
Input: {"tokens":["3","-4","*"]}
Expected Output: -12
Explanation: Multiplication.