TLE (Partially Correct) Please someone expalin the reason


#1

unordered_map<int,int> mp;
TreeNode* func(vector pre, vector in, int l, int r, int& index)
{
if(l>r)
return NULL;

TreeNode* root = new TreeNode(pre[index++]);

if(l==r)
    return root;

root->left = func(pre,in,l,mp[root->val]-1,index);
root->right = func(pre,in,mp[root->val]+1,r,index);

return root;

}

TreeNode* Solution::buildTree(vector &pre, vector &in) {
mp.clear();
int index = 0;
int n=pre.size();
for(int i=0;i<n;i++)
mp[in[i]]=i;
return func(pre,in,0,n-1,index);
}