← Google Interview Insights

Google·Software Engineer·Technical Phone Screen·Senior

SeniorPrefer not to say
May 2026

Summary

Google SWE interview with a string manipulation problem that looks straightforward until you actually try to get the parenthesization exactly right. One question, but it had enough depth to keep me busy for the whole session.

Questions Asked (1)

Q1

Given a string in reverse Polish notation (e.g. "2,1,+,3,*"), convert it to an equivalent infix expression with no unnecessary parentheses (e.g. "(2+1)*3").

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

The stack-based conversion part I got pretty quickly.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a stack to evaluate the RPN expression while building an expression tree. Then perform an in-order traversal of the tree, adding parentheses only when the child operator has lower precedence than the parent, or when associativity requires it (e.g., right child of '-' or '/').

Pro tip: Clarify the input format and operator precedence/associativity upfront, and mention that you'd handle edge cases like unary minus or invalid expressions. This shows attention to detail and real-world robustness.

1. Parse and build expression tree

Iterate through the RPN tokens. For each operand, push a leaf node; for each operator, pop two nodes, create an operator node with them as children, and push it back. The final stack top is the root.

2. Define precedence and associativity

Assign precedence levels (e.g., +,-:1; *,/:2) and note that all operators are left-associative. This determines when parentheses are needed.

3. Generate infix with minimal parentheses

Recursively traverse the tree in-order. For each operator node, decide whether to parenthesize its left and/or right child based on precedence and associativity rules.

4. Handle edge cases and validate

Consider unary operators, division by zero, and invalid RPN. Optionally, verify by converting back to RPN or evaluating both expressions.

Key Points to Mention

  • Stack-based evaluation of RPN to build an expression tree
  • Operator precedence and associativity rules for minimal parentheses
  • In-order traversal with conditional parentheses
  • Time and space complexity: O(n) for both
  • Handling of edge cases like unary minus or invalid input
  • Trade-offs: tree vs. direct string manipulation

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