Given an input string up to 25 characters long consisting of characters A-Z, output its index in the alphabetically sorted list of all possible anagrams of the input string. Input string is not case sensitive. Input characters can be repeated. The app must complete in less than 500ms and take less than 1GB of memory.
At first glance this looks impossible to do without an arbitrary precision math library. The worst case input is 25 unique characters, resulting in 25! possible anagrams. 25! is orders of magnitude larger than 2^64. Because the relationship between the indexes and the strings is not direct and must be calculated, there is no way to simply convert the string to a number.
This comes from an interview challenge I got the other day. I couldn't come up with a solution for them and they insisted that there is indeed a good solution...