Tom Ritchford
Oct 26, 2023

--

But what about a DB candidate who doesn't know what a join is?

It's very hard to think of any tree problem that is easier than this one. Here’s a solution in Python, if your trees are nested lists of integers:

def invert(tree: list[int] | int) -> list:
if isinstance(tree, int):
return tree
return [invert(i) for i in reversed(tree)]

Note that “inverting a tree” isn’t actually a thing in computer science. It only exists in this problem, and is defined to the candidate with the problem.

I’ve given hundreds of technical interviews, perhaps over a thousand, in 40 years in the business. It’s surprisingly hard to come up with a question that’s easy enough to solve in a 45-minute interview, but isn’t actually trivial.

--

--

Responses (1)