Problem in the compiler - C++


#1

I think there is a problem in the compiler. I wrote the code and after pressing the test button, it is giving runtime error on test case A : [ 1, 2, 3, 4, 5 ] B : [ 3, 2, 4, 1, 5 ], But when I put the same input in the custom test case field, It is giving the correct output. If anyone else is also facing the same issue, please let me know. Here is my code -->

/**

  • Definition for binary tree
  • struct TreeNode {
  • int val;
    
  • TreeNode *left;
    
  • TreeNode *right;
    
  • TreeNode(int x) : val(x), left(NULL), right(NULL) {}
    
  • };
    */

int search(vector &ino,int x,int s,int e)
{

for(int i=s;i<=e;i++)
{
    if(ino[i]==x)
    {
        return i;
    }
}

}

int ind=0;

TreeNode* prein(vector &pre, vector &ino,int s,int e)
{

if(s>e)
{
    return NULL;
}



TreeNode* root=new TreeNode(pre[ind]);
int ind1=search(ino,pre[ind],s,e);


ind++;

root->left=prein(pre,ino,s,ind1-1);
root->right=prein(pre,ino,ind1+1,e);


return root;

}

TreeNode* Solution::buildTree(vector &pre, vector &ino) {

TreeNode* root=prein(pre,ino,0,ino.size()-1);

return root;

}