← DoorDash Interview Insights

DoorDash·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Apr 2026

Summary

DoorDash coding round for a software engineer position. One question, arithmetic expression evaluator, and it was a tighter problem than it looks on the surface.

Questions Asked (1)

Q1

Given a string representing a valid arithmetic expression with non-negative integers and the operators +, -, *, / but no parentheses, evaluate it and return the integer result. Division truncates toward zero. The string may contain whitespace.

Algorithms & Data Structures
Author's notes

I knew the general idea but fumbled the operator precedence part for a bit.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a stack to handle operator precedence by evaluating multiplication and division immediately, while deferring addition and subtraction. Parse the string in one pass, maintaining the current number and the last operator, and push results onto the stack. Finally, sum the stack to get the result.

Pro tip: Clarify edge cases upfront, such as division truncation toward zero (e.g., -3/2 = -1) and handling of whitespace, to show attention to detail. Also, mention that you can optimize space by using a variable instead of a stack for the running sum, but a stack is clearer for explaining.

1. Clarify requirements and edge cases

Confirm that the expression is valid, contains only non-negative integers, operators +, -, *, /, and whitespace, and that division truncates toward zero. Discuss potential edge cases like single number, leading/trailing spaces, and large numbers.

2. Choose data structures and algorithm

Decide to use a stack to store intermediate results. Explain that multiplication and division have higher precedence, so they are evaluated immediately, while addition and subtraction are deferred by pushing numbers onto the stack.

3. Parse and evaluate in one pass

Iterate through the string, building the current number. When an operator is encountered, apply the previous operator to the top of the stack and the current number, then push the result. Update the operator and reset the number.

4. Handle final number and sum stack

After the loop, apply the last operator to the final number and the stack. Then sum all elements in the stack to get the final result.

5. Analyze complexity and test

State that time complexity is O(n) and space complexity is O(n) in the worst case. Walk through a few test cases, including expressions with mixed operators and division truncation.

Key Points to Mention

  • Operator precedence: multiplication and division before addition and subtraction.
  • Use of a stack to store intermediate results and defer addition/subtraction.
  • Handling of multi-digit numbers and whitespace.
  • Division truncation toward zero and its implementation (e.g., using int() in Python or Math.trunc in Java).
  • Time and space complexity analysis.
  • Edge cases: single number, negative results, and large numbers.

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