← Amazon Interview Insights

Amazon·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
May 2026

Summary

Amazon SWE coding round, just the one question but it was a classic expression parsing problem that I thought I knew better than I did.

Questions Asked (1)

Q1

Implement a basic calculator that can evaluate arithmetic expressions with +, -, *, and / operators on integer operands, without using built-in eval functions.

Algorithms & Data Structures
Author's notes

I've seen this problem before so I thought I'd breeze through it.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem constraints (integer operands, operator precedence, no parentheses) and then propose a two-stack or shunting-yard approach to evaluate the expression in a single pass. Walk through an example to demonstrate correctness and discuss time/space complexity.

Pro tip: Handle edge cases like division by zero, negative numbers, and multi-digit operands explicitly, and mention that you'd write unit tests to validate the solution—this shows production-level thinking that Amazon values.

1. Clarify requirements and constraints

Ask about input format (string, tokens), integer division behavior, operator precedence, and whether parentheses or unary operators are included. Confirm that no eval is allowed.

2. Choose an algorithm

Select a two-stack approach (one for operands, one for operators) or the shunting-yard algorithm to handle precedence. Explain why this works in O(n) time.

3. Walk through the algorithm

Describe step-by-step how to process tokens: push numbers, compare operator precedence, and apply operators when appropriate. Use a small example like '3+5*2' to illustrate.

4. Handle edge cases and errors

Discuss handling division by zero, negative numbers, multi-digit numbers, and invalid expressions. Mention how to return errors gracefully.

5. Analyze complexity and test

State time and space complexity (O(n) time, O(n) space). Suggest test cases to verify correctness, including edge cases.

Key Points to Mention

  • Operator precedence: * and / before + and -
  • Two-stack or shunting-yard algorithm for single-pass evaluation
  • Handling multi-digit integers and negative numbers
  • Division by zero and invalid input handling
  • Time and space complexity: O(n) time, O(n) space
  • Unit testing and edge case validation

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.