Problem Description
Given a string A, find the rank of the string amongst its permutations sorted lexicographically. Note that the characters might be repeated. If the characters are repeated, we need to look at the rank in unique permutations. Look at the example for more details.
NOTE:
your answer % 1000003
where 1000003 is a prime number.1 <= len(A) <= 1000000
First argument is a string A.
Return an integer denoting the rank.
Input 1:
A = "aba"
Input 2:
A = "bca"
Output 1:
2
Output 2:
4
Explanation 1:
The order permutations with letters 'a', 'a', and 'b' : aab aba baa So, the rank is 2.
Explanation 2:
The order permutations with letters 'a', 'b', and 'c' : abc acb bac bca cab cba So, the rank is 4.
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a question? Checkout Sample Codes for more details.