Problem 1028 · Hard

Recover a Tree From Preorder Traversal

Each value carries its depth as leading dashes, so a stack of ancestors rebuilds the tree in one pass.

Open the interactive visualisation