Pergunta de entrevista da empresa Meta

Print the nodes of a binary tree columnwise . For example Input : a / \ b c / \ d e / \ f g Then output is b f a d c g e

Resposta da entrevista

Sigiloso

25 de fev. de 2015

My answer : Store in each node the right column they belong to. That is if you are the left child of your parent then your column number should be your parent's column number-1 else it should be your parent's column numebr +1 .. So, after the algorithm the nodes' value will look liek this 0 / \ -1 1 / \ 0 2 / \ -1 1 Then start from the least value to graetes value printing nodes belonging to this value. The mapping of nodes' value and their name can be done using hash map(the part where i messed up a bit).