heads
with 26 elements, each being an empty list, corresponding to each letter of the alphabet.words
and add it to the list in heads
corresponding to its first letter.matchCount
to 0 to keep track of the number of words that are subsequences of s
.s
:
a. Take the list of words waiting for the current letter.
b. For each word in this list, remove the first letter and move the remaining part to the list corresponding to its next waiting letter.
c. If a word is empty after removing the first letter, increment matchCount
by 1.matchCount
.