Find all nodes that root an undirected acyclic graph as an alternating-color binary tree.
Unlock detailed company stats for this questionUpgrade
There is an undirected acyclic graph. Find all nodes such that, when the graph is rooted at that node:
- It forms a valid binary tree (each node has at most 2 children).
- Each level has a different alternating color, like BWBWB or WBWBWB (all nodes on the same level share one color, and adjacent levels alternate between the two colors).
Follow-up: find the minimum number of node color changes required to meet the conditions.
Expect follow-ups like
- Find the minimum number of node color changes required to meet the conditions.
Community answers
No answers contributed by the community yet.
Related questions
Find the diameter of an acyclic undirected graph (a tree).In a directed graph, find all nodes reachable from a source that are also part of a cycle.Related courses

Course

Course
Course
