Google Interview experience
1 round over 4 weeks. No offer, good experience.
Had a phone screen where the first 5 minutes were introductions and then another 5 mins to go over the question. I was asked the "find the closest value in a binary tree" leetcode question. The last 5-10 mins were for me to go over any questions I had
Problem:
Given a non-empty root of a binary search tree (BST) and a target value k, find the value in the tree that's closest to k
Input: root = [6, 4, 8, 3, 5, None, 9], k = 7.2
6
/ \
4 8
/ \ \
3 5 9
Output: 8Approach:
Start at the root and keep track of the closest value we have found so far. If the current value is greater than k then traverse the left subtree, otherwise traverse the right subtree if it's less than or equal to k. Keep doing this and updating the closest value until we've reached the end of the tree.
Know someone interviewing at Google? Pass it on.
Same company, different candidates.
Share yours while it’s fresh. It takes five minutes, it’s anonymous, and it will help future candidates.