
A full binary tree is a binary tree where every node has exactly 0 or 2 children.
The first and only line contains a single integer ‘N’, denoting the number of nodes required in each tree.
For each test case, print in a separate line all the nodes of the tree. Trees can be printed in any order but all the nodes of a tree must be printed in level order. If a node does not exist, '-1' should be printed in its place. All the trees must be printed in a separate line.
You do not need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 5
1 <= N < 20
Time Limit: 1 sec
The approach is to divide the problem into smaller subproblems. We can observe that if there are ‘N’ nodes and the left subtree have ‘X’ nodes then the right subtree will have ‘N-1-X’ nodes. So for all possible values of ‘X’, we can get trees having ‘X’ nodes in the left subtree and ‘N-1-X’ nodes in the right subtree and thus we can combine these and we can get all trees that contain ‘N’ nodes. We can also observe that if ‘N’ is even, we can not have any full binary tree.