A word is a sequence of letters A-Z. Rearranging the letters in the word, you can come up with new words, composed of the same letters. For example, the letters in the word TESTING can be rearranged to result in SETTING. If we sort all the words made up of the same set of letters alphabetically, we can calculate the rank of each word.
Given a word (not limited to just "dictionary words"), calculate and output its rank among all the words that can be made from the letters of that word. The word can contain duplicate letters.
A string, representing a sequence of letters (A-Z).
An integer, representing the rank of the given word.
ABAB
2
Let's create a list of all the words that can be made up of the letters of the input and sort them alphabetically:
- AABB
- ABAB
- ABBA
- BAAB
- BABA
- BBAA
The given word is number 2 in the list.