1
We can't create Full Binary tree with even number of nodes. e.g n = 2/4/6/8...2
start with cache having n = 117
def allPossibleFBT(self, n: int) -> List[Optional[TreeNode]]:21
# We use result array to store all possible binary tree of size n23
leftNodes, rightNodes = 1,n-224
# if n = 7 then, (leftNodes,rightNodes) should be : (1,5),(3,3),(5,1) 27
if leftNodes not in cache:29
if rightNodes not in cache:31
leftTree = cache[leftNodes]32
rightTree = cache[rightNodes]33
# Using two for loops we generate all possible binary tree.34
# Always remember root of each binary tree is diffrent, So create new root every time35
for i in range(len(leftTree)):36
for j in range(len(rightTree)):37
root.left = leftTree[i]38
root.right = rightTree[j]49
cache = {1:[TreeNode()]}