A spam filter looks for a keyword hidden inside a message by spreading its letters out. A hidden copy is a choice of positions in text, in increasing order, whose letters spell keyword exactly. Two copies are different if they use a different set of positions.
Write countHiddenCopies(text, keyword) that returns the number of hidden copies, modulo 1000000007.
Input: text = "aab", keyword = "ab" Output: 2
The b can follow the first a or the second a.
Input: text = "abc", keyword = "d" Output: 0
The keyword's letter never appears.
1 <= text.length, keyword.length <= 2500Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #568 Count Hidden Copies of a Keyword. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.