Hidden Word Count
Return the number of ways to choose positions in text that spell word when read from left to right (that is, as a subsequence of text). Two ways are different when they use different sets of positions, even if the letters picked look the same. The empty word can be spelled in exactly one way, and a word that cannot be spelled gives 0.
For example, text = "baab" and word = "ab" give 2: the a at position 1 or the a at position 2, each followed by the final b.
Example 1
text "baab"
word "ab"
returns 2
Positions 1 and 3, or positions 2 and 3, spell ab.
Example 2
text "aaa"
word "a"
returns 3
Each of the three a positions spells the word on its own.
Constraints
0 <= len(text) <= 120 <= len(word) <= 4- Lowercase letters only
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Recursion problems
- Maze EscapeMedium
- Numbers RoundMedium
- Tower MovesMedium
- Tower With a Middle StopMedium
- Where the Trace Can StartMedium
- Crates of Equal WeightHard
- Every Word SquareHard
- Fewest Payments to Settle UpHard