JavaScript 7-line solution
The problem is pretty similar to this problem:\nGiven a string of brackets which only consists of a single type of brackets, determine if it is balanced or not.
The problem is pretty similar to this problem:\n`Given a string of brackets which only consists of a single type of brackets, determine if it is balanced or not. A balanced string of brackets means the total number of open brackets is equal to the total number of close brackets, and while traversing the string from left to right, the number of open brackets is always greater than or equal to the number of close brackets.`\nAt first, we have an empty slot, we can put a number or a `#` to it:\n- Adding a number means removing an empty slot & creating 2 more empty slots, left & right child of the node we just added\n- Adding a `#` just means removing an empty slot, because a NULL value prevents us from creating more nodes in a branch\n\nWhile traversing the tree, if there are no more empty slots at some point, the input is not a correct preorder traversal serialization of a binary tree.\nAfter traversing the whole given input, the input is correct if there are no empty slots.\n```\n/**\n * @param {string} preorder\n * @return {boolean}\n */\nvar isValidSerialization = function(preorder) {\n    let balance = 1\n    for(const node of preorder.split(\',\'))\n        if (balance > 0)\n            if (node === \'#\') --balance\n            else ++balance\n        else return false\n    return balance < 1\n}\n```
['Tree', 'JavaScript']