← Docker Interview Insights

Docker·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jun 2026Remote

Summary

Coding round at Docker for a software engineer role. One algorithmic problem, calculator expression evaluation, no parentheses but operator precedence still matters. Felt manageable once I figured out the right data structure approach.

Questions Asked (1)

Q1

Given a string representing a valid math expression with non-negative integers and the operators +, -, *, and /, implement a calculator that evaluates it correctly (respecting operator precedence, truncating division toward zero, ignoring spaces). No built-in eval allowed.

Algorithms & Data Structures
Author's notes

I stared at this for longer than I should have before realizing the main issue is precedence.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem constraints (e.g., integer division truncation, operator precedence, no parentheses) and then propose a two-stack or two-pass solution. Walk through a simple example to demonstrate correctness, and discuss time/space complexity.

Pro tip: Mention that you would handle edge cases like division by zero and large numbers, and that you'd write unit tests to verify operator precedence and truncation behavior.

1. Clarify requirements and constraints

Confirm that the expression is valid, contains only non-negative integers and +, -, *, /, and that division truncates toward zero. Ask if parentheses are excluded.

2. Choose an algorithm

Decide between a two-stack approach (one for numbers, one for operators) or a two-pass method (first handle * and /, then + and -). Explain why it respects precedence.

3. Implement the chosen approach

Write code that parses the string, ignores spaces, builds numbers, and applies operators with correct precedence. Ensure division truncates toward zero.

4. Test with examples and edge cases

Run through examples like '3+2*2', ' 3/2 ', '3+5 / 2', and edge cases like division by zero or large numbers. Verify results.

5. Analyze complexity and discuss optimizations

State that time complexity is O(n) and space O(n) for the stacks. Mention possible optimizations like using a single stack or recursion if parentheses were allowed.

Key Points to Mention

  • Operator precedence: * and / before + and -
  • Truncation toward zero for division (e.g., 3/2 = 1, -3/2 = -1)
  • Ignoring spaces in the input string
  • Handling multi-digit numbers and negative results
  • Using a stack to store intermediate results or operators
  • Time and space complexity analysis

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