Google Software Development Intern 2026, Round-1(Question & Answer)
Summary
I had my first round interview for a Software Development Intern position at Google. I was given a complex Binary Tree problem involving node value manipulation, node swapping, and subtree removal based on the mode. I successfully solved it, achieving O(n) time and space complexity, and also discussed a follow-up question on swapping two numbers.
Full Experience
I recently had my first-round interview for the Software Development Intern position at Google. The interview lasted 45 minutes. I was presented with a challenging Binary Tree problem that required me to implement several operations. First, I needed to replace each node's value with its reciprocal. Second, I had to swap the left and right children of each node (not their values). Finally, if a node's value was the arithmetic mode (the most repeated value in the entire tree), I had to remove that node and its entire subtree.
I managed to solve the problem efficiently, achieving O(n) time and space complexity by using a map for frequency counting and then traversing the tree to apply the transformations and removals. My solution involved a helper function to count frequencies and another to perform the transformations recursively.
The interviewer also asked a follow-up question on how to implement a function to swap two numbers.
Interview Questions (2)
Given a Binary Tree where all nodes have float64 values, implement the following operations:
- Replace each node's value with its reciprocal.
- Swap the left and right children of each node (not their values).
- If a node's value is the arithmetic mode (the most repeated value in the entire tree), remove that node and its entire subtree.
The solution should handle basic constraints and consider non-zero division for reciprocals.
How would you implement a function to swap two numbers?