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

Interview Code Editor
Hints
  • Hint 1
  • Solution Approach
  • Complete Solution
2916 successful submissions.
Asked In:
  • Housing
  • Zenefits
Click here to jump start your coding interview preparation