#2930

Number of Strings Which Can Be Rearranged to Contain Substring

specialist · 790 · lc medium +31 · verified · 57% accepted · 188 likes · top 52%

Description

Given an integer n, a string of length n using only lowercase English letters is called good if some permutation of it contains "leet" as a contiguous substring.

For example, "lteer" is good (rearranges to "leetr"), but "letl" is not.

Count all good strings of length n and return the result modulo 109 + 7.

Example 1:

Input: n = 4
Output: 12
Explanation: The 12 strings which can be rearranged to have "leet" as a substring are: "eelt", "eetl", "elet", "elte", "etel", "etle", "leet", "lete", "ltee", "teel", "tele", and "tlee".

Example 2:

Input: n = 10
Output: 83943898
Explanation: The number of strings with length 10 which can be rearranged to have "leet" as a substring is 526083947580. Hence the answer is 526083947580 % (109 + 7) = 83943898.

Code

1
2
3