


There is no restriction on how you encode/decode the N-ary tree.
N-ary Tree is given as follows:-
6
1 -1 2 3 4 -1 5 -1 6 -1 -1 -1 -1
The above N-ary tree and its encoded binary tree can be represented as follows:-

The above binary tree can be represented as follows in their level order traversal:-
1
2 -1
5 3
-1 -1 6 4
-1 -1 -1 -1
The first line contains a single integer ‘T’ representing the number of test cases.
The first line of input contains the elements of the tree in the level order form separated by a single space.
N-ary Tree is represented in their level order traversal. Each group of children is separated by -1.

1 -1
2 3 4 -1
5 -1 6 -1 -1
-1 -1
The sequence will be put together in a single line separated by a single space. Hence, for the above-depicted tree, the input will be given as:
1 -1 2 3 4 -1 5 -1 6 -1 -1 -1 -1
For each test case, for Encode function/method: return the binary tree. For Decode function/method: return the N-ary tree
1. The list/array storing binary tree must contain ‘N' + 1 element as nodes are numbered from 1 to ‘N’. The 'i'th element of the list/array must contain first the left child then the right child.
2. If a node does not have a left/right child just display that child as -1.
3. You do not need to print anything; it has already been taken care of. Just implement the function.
1 <= T <= 10
1 <= N <= 1000
Time Limit: 1 sec
We will convert the N-ary tree to a binary tree as follows:
We can decode from binary tree to N-ary tree. 1’s left child is the leftmost child of 1 in the N-ary tree. 3 and 4 are siblings of 2. 5’s leftmost child of 2 in the N-ary tree. 6’s leftmost child of 3 in the N-ary tree. In this way, we can decode the N-ary tree from the binary tree.
The steps are as follows:
Second Largest in Tree Level
Sorted Doubly Linked List to Balanced BST
Corporate Skill Diversity
Longest Substring with K-Repeating Characters
Expression Add Operators