Two questions.
The first was to merge an n-ary tree by key -- only nodes that share the same key get merged. It's solvable with DFS. Make sure to ask about the corner cases up front, like whether the root keys are even the same.
The second question was similar in spirit. The interviewer completely did not understand this problem. I wrote out the following conversion formula, which lets you solve it in one DFS pass instead of two:
sum(num * (maxDepth - (the depth of the integer) + 1))
=> sum(num) * (maxDepth + 1) - sum(num*depth)
I explained it until I was blue in the face, but he just could not follow how this formula was derived... His level was honestly pretty bad. He also told me he wasn't very familiar with Python.
For both problems I wrote optimal solutions, walked through the corner cases, and dry-ran the test cases. Got rejected a week later.
Discussion
Loading comments…