Back to problems

Build Binary Tree from Edges / S-Expression

Algorithm · Optiver · Hard

Requirements The input consists of (parent, child) entries, with the parent appearing first; it arrives as an arbitrary string that must be parsed and checked for validity. When the text is invalid or the pairs cannot form a valid binary tree, return the highest-precedence error from the following list: E1: Invalid Input String E2: Duplicate Pair E3: A parent has more than 2 children E4: Multiple Roots E5: Cycle in the Tree If both E4 and E5 apply, report E4. When no error…

Checking your access…