Bug: Submission tool states wrong answer but same testcase works as custom.

This is regarding problem https://leetcode.com/explore/learn/card/data-structure-tree/133/conclusion/995/

Test Case:
Input: [1]

LeetCode submission shows:
Output: []
Expected: [1]

However, when same case is done via custom test case, the output and expected are matching viz. [1]

My Code:

public class Codec {
 private static int index = 0;
    // Encodes a tree to a single string.
    public String serialize(TreeNode root) {
        if(root == null){
            return "null,";
        }
        return root.val + ","+ serialize(root.left)  + serialize(root.right);
    }

    // Decodes your encoded data to tree.
    public TreeNode deserialize(String data) {
        System.out.println(data);
        List<String> ls = Arrays.asList(data.split(","));
        return deserializeHelper(ls);
    }
    
    private TreeNode deserializeHelper(List<String> ls){
        if(index>=ls.size() || "null".equals(ls.get(index))){
            return null;
        }
        TreeNode n = new TreeNode(Integer.valueOf(ls.get(index)));
        index++;
        n.left = deserializeHelper(ls);
        index++;
        n.right = deserializeHelper(ls);
        return n;
            
    }
}

How is it possible that the testcase via custom testcase works but not the actual solution?

Comments (1)