Design an encoding to convert an N-ary tree to a binary tree and back.
Design an algorithm to encode an N-ary tree to a binary tree, and decode it back. Each node in an N-ary tree can have multiple children, but in a binary tree each node has at most 2 children.
Examples
Input:[[],0]
Output:[0,0,0,0,0]
Input:[[0],0]
Output:[0,0,0,0,1]
Hints
Use left-child right-sibling representation.
First child becomes left child, siblings become right children.