Sorted Permutation Rank

Given a string, find the rank of the string amongst its permutations sorted lexicographically.
Assume that no characters are repeated.

Example :

Input : 'acb'
Output : 2

The order permutations with letters 'a', 'c', and 'b' : 
abc
acb
bac
bca
cab
cba

The answer might not fit in an integer, so return your answer % 1000003

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 doubt? Checkout Sample Codes for more details.
Start solving Sorted Permutation Rank on Interview Code Editor
Sign Up
to access hints and editorial solutions for Sorted Permutation Rank
4392 successful submissions.
Asked In:
  • Housing
  • Zenefits
Click here to start solving coding interview questions