Pergunta de entrevista da empresa Texas Instruments

How do you find the distance between two nodes in a Binary Tree?

Resposta da entrevista

Sigiloso

20 de out. de 2021

You start at the root node and recursively search until you find the first item you want. Once you've done that you just need to keep track of each element in the path to that node. With the paths you can count compare each node in the path to the other path to find their lowest common ancestor. Once you've done that its just adding the nodes to the lowest common ancestor.