← Docker Interview Insights

Docker·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Interviewed for a software engineer role at Docker and got a calculator problem that looks easy until you remember operator precedence is a thing. No parentheses at least, but still had to think carefully about how to handle multiplication and division before addition and subtraction.

Questions Asked (1)

Q1

Given a string representing a valid mathematical expression with non-negative integers and the operators +, -, *, and /, evaluate it and return the result. Integer division should truncate toward zero. No parentheses, no built-in eval.

Algorithms & Data Structures
Author's notes

My first instinct was to just scan left to right and accumulate, which obviously breaks the moment you hit a * or /.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify constraints and edge cases first, then propose a two-pass or stack-based solution that respects operator precedence. Walk through a small example to validate the logic, and discuss time/space complexity before coding.

Pro tip: Mention that you'd handle integer division truncation carefully (e.g., using trunc() or adjusting for negative results) and that you'd test with expressions like '14-3/2' to catch precedence bugs.

1. Clarify requirements and edge cases

Ask about input format, whitespace, negative numbers, division by zero, and overflow. Confirm that division truncates toward zero and that no parentheses exist.

2. Choose an algorithm

Decide between a two-pass approach (first handle * and /, then + and -) or a stack-based single pass. Explain why operator precedence matters.

3. Walk through an example

Trace a sample expression like '3+2*2' to demonstrate how the algorithm processes tokens and maintains intermediate results.

4. Analyze complexity and trade-offs

State O(n) time and O(n) space for the stack approach, or O(1) space for the two-pass if modifying input is allowed. Discuss pros and cons.

5. Code and test

Write clean code with clear variable names, then test with edge cases like single number, division truncation, and mixed operators.

Key Points to Mention

  • Operator precedence: * and / before + and -
  • Integer division truncation toward zero (e.g., 7/2=3, -7/2=-3)
  • Handling multi-digit numbers and whitespace
  • Using a stack to store intermediate results
  • Time and space complexity analysis
  • Edge cases: division by zero, overflow, single number

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