Given the root of a binary tree, flatten it into a 'linked list' in place: every node's left child becomes null and its right child points to the next node in preorder order. Return the flattened tree as a level-order array (which will be a right-leaning chain). The tree is given as a level-order array.
Input: A level-order array of the tree.
Output: Array — the flattened right-chain tree in level order.
Input: [1,2,5,3,4,null,6]
Output: [1,null,2,null,3,null,4,null,5,null,6]
Explanation: Preorder chain to the right.Input: [1]
Output: [1]
Explanation: Single node.Input: []
Output: []
Explanation: Empty tree.0<=nodes<=2000-100<=value<=100