 Ways to split string such that each partition starts with distinct letter
Submissions: 1185   Accuracy: 12.69%   Difficulty: Easy   Marks: 2

Given a string s. Let k be the maximum number of partitions possible of the given string with each partition starts with a distinct letter. The task is to find the number of ways string s can be split into k partition (non-empty) such that each partition starts with a distinct letter. Print number modulo 1000000007

Input:
The first line contains an integer T, the number of test cases. For each test case, there is a string s.

Output:
For each test case, the output is the maximum number of ways modulo 1000000007.

Constraints:
1<=T<=100
1<=s.length()<=10^3
'A'<=s[i]<='z'
Note: String is not case sensitive.

Example:
Input

2
abB
abbcc
Output
2
4

Explanation
1.
"abB" can be maximum split into 2 partitions {a, bB} with distinct starting letter, so k = 2. And, the number of ways to split "abb" into 2 partitions with distinct starting letter is 2 that are {a, bB} and {ab, B}.
2.  "abbcc" can be maximum split into 3 partitions with distinct letter, so k=3. Thus the number of ways to split "abbcc" into 3 partitions with distinct letter is 4 i.e. {ab, b, cc}, {ab, bc, c}, {a, bb, cc} and {a, bbc, c}.

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Vanshika Sharma
Author: Vanshika_pec

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.