Problem 2764 · Medium

Is Array a Preorder of Some Binary Tree

Read the node-parent pairs in order while a stack holds the open path from the root; a parent that is no longer open, or a third child, rules the order out.

Open the interactive visualisation