Flatten Binary Tree to Linked List

Medium · Trees · about 20 minutes

Asked at Meta, Microsoft, Google, Amazon, Bloomberg.

Rewire a binary tree in place so it becomes a single chain going right: every left pointer is set to null, and following the right pointers visits the nodes in pre-order. Return the root.

Related guides