Find a valid root for a tree-shaped graph.
Unlock detailed company stats for this questionUpgrade
Given a connected acyclic graph where every node has at most 3 neighbours, find a valid node that forms a binary tree as root.
Expect follow-ups like
- Now every node is either black or white, and at every depth in the tree colors must alternate. Find a valid node.
- Now the graph can be disconnected.
- Now every node is red, black or white, and the only allowed depth sequence is RWB RWB..., with the root of any color. Find a valid root.
Format · 45-minute DSA round; solve, code and discuss complexity per follow-up.
Community answers
No answers contributed by the community yet.
Related courses

Course

Course
Course
