A search box receives queries typed without spaces, such as searchbox. To suggest interpretations, it counts every way to cut query into words from the list words, where each word may be used any number of times.
Write countSegmentations(query, words) that returns the number of different ways to cut the query so that every piece is a word, modulo 1000000007. Two ways are different if they cut at different positions.
Input: query = "searchbox", words = ["search","box","sear","ch","s","earch"] Output: 3
search + box, sear + ch + box, and s + earch + box.
Input: query = "abc", words = ["ab"] Output: 0
After ab, the c is not a word.
1 <= query.length <= 10001 <= words.length <= 10001 <= words[i].length <= 20, all differentRun tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #548 Count Search Query Segmentations. 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.