Recently failed my Google Screening

The question was :

you are given a undirected acyclic graph, each node in the graph can have at most 3 neighbors, find the node in the graph after setting that node a root, the graph will convert in to a binary tree.

I gave a solution but it was O(N^2).

can anyone help me with the solution

Comments (7)