Evaluate an arithmetic expression
Company: Docker
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This question evaluates parsing and expression-evaluation skills, specifically handling operator precedence, integer division truncation, multi-digit numbers, and whitespace handling within the Coding & Algorithms domain.
Constraints
- Expression has no parentheses and is valid
Examples
Input: ('3+2*2',)
Expected Output: 7
Explanation: Multiplication before addition.
Input: (' 3/2 ',)
Expected Output: 1
Explanation: Truncates toward zero.
Input: (' 3+5 / 2 ',)
Expected Output: 5
Explanation: Prompt example.
Input: ('14-3/2',)
Expected Output: 13
Explanation: Division before subtraction.
Hints
- Collapse multiplication/division onto the previous stack term; sum additive terms at the end.