← Google Interview Insights

Google·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Apr 2026

Summary

Google SWE coding round, one question on stack-based expression parsing. Pretty straightforward if you know your stacks, but the output format tripped me up a bit.

Questions Asked (1)

Q1

Given a string in reverse Polish notation (e.g. "2,1,+,3,*"), convert it to a fully parenthesized infix expression (e.g. "(2+1)*3").

Algorithms & Data Structures
Author's notes

I knew it was stack-related pretty fast but fumbled the parentheses logic for a minute.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a stack to evaluate the RPN expression, but instead of computing numeric values, build expression trees or strings. For each token, if it's an operand, push it; if it's an operator, pop two operands, combine them into a parenthesized expression, and push the result. At the end, the stack contains the fully parenthesized infix expression.

Pro tip: Clarify the expected handling of multi-digit numbers and negative numbers, and mention that you assume valid RPN input. Also, discuss whether to add parentheses around every operation or only when necessary for precedence, but for fully parenthesized, always add them.

1. Understand the problem and clarify assumptions

Restate the problem: convert a comma-separated RPN string to a fully parenthesized infix string. Ask about input format (e.g., multi-digit numbers, negative numbers, spaces) and confirm that the output should have parentheses around every binary operation.

2. Choose the right data structure

Use a stack to store intermediate expressions. Each element can be a string representing a sub-expression. This naturally handles the postfix evaluation order.

3. Process tokens sequentially

Split the input string by commas. For each token: if it's a number, push it onto the stack; if it's an operator, pop the top two elements (right operand first, then left), form a string like '(left op right)', and push it back.

4. Handle edge cases and return result

After processing all tokens, the stack should contain exactly one element: the final infix expression. If the stack has more or fewer, the input was invalid. Return that string.

5. Analyze complexity and test

Time complexity is O(n) where n is the number of tokens, as each token is processed once. Space complexity is O(n) for the stack and output strings. Walk through an example to verify correctness.

Key Points to Mention

  • Stack-based evaluation of postfix expressions
  • Order of operands: when popping, the first pop is the right operand, the second is the left
  • String concatenation to build parenthesized expressions
  • Handling multi-digit numbers and negative numbers (if applicable)
  • Time and space complexity analysis
  • Edge cases: single number, invalid expression, division by zero (not relevant here but good to mention)

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