Build a binary tree from parent-child relationship triples and return its root.
You are given a list of descriptions, where each description has the form [parent, child, isLeft].
Each triple means that child is attached to parent as:
isLeft = 1isLeft = 0The descriptions describe one valid binary tree. Your task is to reconstruct the tree and return its root node.
A node value may appear multiple times across descriptions. Every node has a unique value, and exactly one node is the root of the final tree.
descriptions[i] = [parent, child, isLeft]parent and child are integer node valuesisLeft is either 0 or 11 <= descriptions.lengthExample 1
Input
descriptions = [[20,15,1],[20,17,0],[15,10,1]]
Output
root = [20,15,17,null,10]
Explanation
Node 20 has children 15 and 17. Node 15 has left child 10. The only value that never appears as a child is 20, so it is the root.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.