Interview LCA Problem

Sometimes I come across interview questions such as this : "Find the common parent of any two nodes in the tree." I noticed that they are asking LCA questions also on Google, Amazon, etc.

As wikipedia says, an LCA can be found by crossing paths from given nodes to the root and takes O (H), where H is the height of the tree. In addition, there are more complex algorithms that process trees in O (N) and respond to LCA requests in O (1).

Interestingly, it is the interviewers who want to know about the candidates asking this question by the LCA. The first path crossing algorithm seems trivial. Do they expect candidates to remember preprocessing algorithms? Do they expect candidates to invent these algorithms and data structures on the fly?

+3
source share
2 answers

They want to see what you are made of. They want to see how you think, how you solve the problem, and deal with stress from the deadline. I believe that if you solve the problem because you already know the solution, they simply present you with another problem. This is not the solution they want; it is your brain.

+9
source

( ) . , , .

: , " X", " ". : , X, , , , , , , .

- , , - , . , , .

+2

Source: https://habr.com/ru/post/1782171/


All Articles