PROBLEM STATEMENT
John and Brus are studying string theory at the university. According to Brus, a string is called
lucky if no two consecutive characters are equal. John is analyzing a string s, and he wants to
know how many distinct lucky strings can be generated by reordering the letters in s. If s is a
lucky string in its original ordering, it should also be considered in the count.
DEFINITION
Class:TheLuckyString
Method:count
Parameters:string
Returns:int
Method signature:int count(string s)
CONSTRAINTS
-s will contain between 1 and 10 characters, inclusive.
-Each character of s will be a lowercase letter ('a' - 'z').
EXAMPLES
0)
"ab"
Returns: 2
Two lucky strings - "ab" and "ba".
1)
"aaab"
Returns: 0
It's impossible to construct a lucky string.
2)
"aabbbaa"
Returns: 1
"abababa" is the only lucky string that can be generated.
3)
"abcdefghij"
Returns: 3628800
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.