Lucky Strings
InterviewTime limit2sMemory limit256 MB
Count the distinct rearrangements of a short string (length up to 10) that have no two adjacent equal characters.
- Level
Medium4 of 10
- Topics
- Backtracking, Combinatorics, String
- Solved
- No attempts yet
Problem
Minsik and Junyoung are studying strings in their room. Call a string lucky if no two adjacent characters in it are the same.
Junyoung starts analyzing a string S. He wants to know how many different lucky strings can be made by rearranging all characters of S. If the original string S is already lucky, it is also counted.
Input
The first line contains the string S. The length of S is at most 10, and S consists only of lowercase English letters.
Output
Print the number of different lucky strings that can be obtained by rearranging the characters of S.