Sponsored
Use these hints if you're stuck. Try solving on your own first.
If you notice carefully in the flattened tree, each node's right child points to the next node of a pre-order traversal.
Solve with full IDE support and test cases