Binary Tree from preorder and inorder traversal

Hi, the code which i have written successfully compiled and ran but it is failing for test case 3, please help to resolve the issue

mapper = dict() index = -1 class Node: def init(self,data): self.data = data self.left=self.right=None def createTree(inorder,postorder,s,e): global mapper,index if s>e: return None curr = postorder[index] node = Node(curr) index-=1 iIndex = mapper[curr] node.right = createTree(inorder,postorder,iIndex+1,e) node.left = createTree(inorder,postorder,s,iIndex-1) return node def preorder(root): if root==None: return print(root.data,end = " ") preorder(root.left) preorder(root.right) n = int(input()) inorder = list(map(int,input().split())) postorder = list(map(int,input().split())) for i in range(n): mapper[inorder[i]] = i index=len(postorder)-1 root = createTree(inorder,postorder,0,n-1) preorder(root)

@deepaksrawat1906, hi this is Talha shamim I’m TA of CPP but by mistake in the system i recieved your doubts you may ask it again
Sorry for the inconveniences.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.