[Java] Recursive solution (single pass)
java\nclass Solution {\n    \n    int pos = 0;\n    \n    boolean validate(String[] arr) {\n        if (pos == arr.length)\n            return false;\n        \
```java\nclass Solution {\n    \n    int pos = 0;\n    \n    boolean validate(String[] arr) {\n        if (pos == arr.length)\n            return false;\n        \n        //If null node\n        if (arr[pos].equals("#")) {\n            ++pos;\n            return true;\n        }\n        else {\n            ++pos;\n            //The nodes immediately following current node must be its left and right children.\n            boolean isLeftChildValid = validate(arr), isRightChildValid = validate(arr);\n            return isLeftChildValid && isRightChildValid;\n        }\n    }\n    \n    public boolean isValidSerialization(String preorder) {\n        String[] input = preorder.split(",");\n        //Even if the function returned true, the input is invalid if any part of it is unused.\n        return validate(input) && pos == input.length;\n    }\n}\n```
['Recursion', 'Java']