295. Count Generalized Abbreviations (Modulo 10^9+7)

HardStringString

A generalized abbreviation of a word replaces any number of non-overlapping, non-adjacent (in terms of being merged) substrings with their lengths. Each character independently is either kept or part of an abbreviated run, giving 2^n possible abbreviations for a word of length n. Given a word, return the number of generalized abbreviations, modulo 10^9+7.

Input: A quoted word string.

Output: Integer — count mod 10^9+7.

Examples

Example 1
Input: "word"
Output: 16
Explanation: 2^4 = 16 abbreviations.
Example 2
Input: "a"
Output: 2
Explanation: 'a' or '1'.
Example 3
Input: "abc"
Output: 8
Explanation: 2^3 = 8.

Constraints

Asked by

AmazonGoogleMicrosoftMetaAdobe
Solve this problem in the editor →