JavaScript using Next Letter Pointers
Time Complexity: O(S + W) where W is the sum of each word in words array\nSpace Complexity: O(W)\njavascript\nvar numMatchingSubseq = function(S, words) {\n    
Time Complexity: `O(S + W)` where `W` is the sum of each word in `words` array\nSpace Complexity: `O(W)`\n```javascript\nvar numMatchingSubseq = function(S, words) {\n    const bucket = [...Array(26)].map(() => []);\n    let counter = 0;\n    \n    function getCharId(char) {\n        return char.charCodeAt() - \'a\'.charCodeAt()\n    }\n    \n    for(let word of words) {\n        const idx = getCharId(word[0]);\n        bucket[idx].push(word);\n    }\n    \n    for(let char of S) {\n        const idx = getCharId(char);\n        const currBucket = bucket[idx]\n        bucket[idx] = []\n        \n        for(let word of currBucket) {\n            word = word.slice(1);\n            if(!word.length) {\n                counter++;\n                continue;\n            }\n            const nextIdx = getCharId(word[0]);\n            bucket[nextIdx].push(word)\n        }\n    }\n    return counter;\n};\n```
['JavaScript']