I don't understand what is the issue in my solution , JAVA


#1

static int preIndex=0;
public TreeNode buildTree(ArrayList A, ArrayList B) {

    return constructTreeUtil(B , A , 0 ,  A.size()-1);
}

 private  TreeNode constructTreeUtil(ArrayList<Integer> in, ArrayList<Integer> pre, int start, int end) {
    if (start > end)
        return null;

    TreeNode node = new TreeNode(pre.get(preIndex++));
   
    if (start == end)
        return node;
    int index = search(in, start, end, node.val);

    node.left = constructTreeUtil(in, pre, start, index - 1);
    node.right = constructTreeUtil(in, pre, index + 1, end);
    return node;
}

private int search(ArrayList<Integer> arr ,  int start , int end , int value){
    int index;
    for(index = start ; index <= end ; index++)
        if(arr.get(index) == value)
            return index;

    return index;
}

#2

Hey Saurabh! Your code seems to be correct. What is the error that you’re getting?