Build a binary tree · Compiler
Build a binary tree
Build a binary tree from attachment instructions. Begin at its root and follow the path one character at a time: L follows the current node's left child and R follows its right child. A dot in place of the path means stay at the root.
- Input
- Read n rootValue (1 <= n <= 100). The root has ID 1. For each new ID i from 2 through n, read parentID side value. Attach node i to the indicated empty side (L or R) of an existing parent with ID less than i. Values are integers in [-1000, 1000]. Finally read a single token: a path of 1 to 100 L/R characters, or a single dot.
- Output
- Print the value reached, or NONE if any step requires a missing child.
Compiler Explorer runs your code when you run or check it.
Loading your exercise draft…