Given a binary tree in level-order array form (using null for missing children), flatten it into a linked list following the tree's preorder traversal, where each node's right pointer is the next preorder node and left pointers are null. Return the resulting sequence of values. The input is JSON {tree}.
Input: JSON {tree}.
Output: Array — the preorder sequence after flattening.
Input: {"tree":[1,2,5,3,4,null,6]}
Output: [1,2,3,4,5,6]
Explanation: Preorder traversal order.Input: {"tree":[0]}
Output: [0]
Explanation: Single node.Input: {"tree":[1,null,2,null,3]}
Output: [1,2,3]
Explanation: Already right-leaning.0<=nodes<=2000