← Google Interview Insights

Google·Software Engineer·Onsite - Coding / Algorithms·Intermediate

IntermediatePrefer not to say
Jun 2026

Summary

Google SWE coding round, basically a calculator problem that sounds easy until you actually have to handle all the garbage edge cases they throw at you. Spent a lot of time at the whiteboard before writing a single line.

Questions Asked (1)

Q1

Implement a string expression evaluator that handles non-negative integers and the operators +, -, *, / with correct operator precedence, plus edge cases like empty input, whitespace-only strings, trailing operators, and division by zero.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

The base problem is basically a known leetcode question but they layered on a bunch of extras.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify requirements and edge cases, then propose a two-stack or recursive descent approach that respects operator precedence. Walk through the algorithm step-by-step, handle edge cases explicitly, and analyze time/space complexity.

Pro tip: Mention that you would use a sentinel value or exception for division by zero and discuss how to handle it gracefully, showing you think about robustness and user experience.

1. Clarify requirements and edge cases

Ask about input format, expected output, and how to handle edge cases like empty input, whitespace, trailing operators, and division by zero. Confirm whether unary operators or parentheses are needed.

2. Choose an algorithm

Select a two-stack approach (operands and operators) or recursive descent parsing to handle operator precedence. Explain why it works and its time/space complexity.

3. Walk through the algorithm

Describe how to process tokens: push numbers, apply operators based on precedence, and handle parentheses if applicable. Show how to evaluate the expression step by step.

4. Handle edge cases

Explicitly address empty input, whitespace-only strings, trailing operators, and division by zero. Discuss how to detect and respond to each case (e.g., return 0, throw an error, or return a special value).

5. Analyze and optimize

State time and space complexity (O(n) time, O(n) space). Mention potential optimizations or alternative approaches, and discuss trade-offs.

Key Points to Mention

  • Operator precedence and associativity rules
  • Two-stack algorithm or recursive descent parsing
  • Handling of empty input and whitespace-only strings
  • Detection and handling of trailing operators
  • Division by zero handling (exception or sentinel value)
  • Time and space complexity analysis

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