Loading...
Loading...
Loading...
A word S and a pattern T are given. Count the ways to pick positions in S, from left to right, so that the letters at those positions spell T. Two ways are different if they use different positions.
Example
Input
rabbbit rabbit
Output
3
Three ways to choose which b is skipped.
Try the problem first. Open one hint at a time.
Let ways[j] be the number of ways to spell the first j letters of T from the part of S read so far.
For each letter of S, go through T from the end and add ways[j - 1] to ways[j] when the letters match.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor