Flatten Binary Tree to Linked List

Flatten a binary tree into a linked list following preorder traversal. Mutate the tree in place so each left pointer is null and the right pointer forms the preorder chain. The returned tree is serialized as a level order array, so a flattened chain appears as alternating values and nulls.

Examples
Input: []
Output: []
Hints

Flatten Binary Tree to Linked List

Flatten a binary tree into a linked list following preorder traversal. Mutate the tree in place so each left pointer is null and the right pointer forms the preorder chain. The returned tree is serialized as a level order array, so a flattened chain appears as alternating values and nulls.