Rank The Permutations
Medium Accuracy: 33.89% Submissions: 3227 Points: 4

Given a string, S find the rank of the string amongst all its permutations sorted lexicographically.The rank can be big. So print it modulo 1000003
Note: Return 0 if the characters are repeated in the string.

Example 1:

Input: S = "abc"
Output: 1
Explaination: It is the smallest 
lexicographically string of the permutation.

Example 2:

Input: S = "acb"
Output: 2
Explaination: This is the second smallest
lexicographically string of the permutation.

Your Task:
You do not need to read input or print anything. Your task is to complete the function rank() which takes string S as input parameter and returns the rank modulo 1000003 of the string.

Expected Time Complexity: O(|S|2)
Expected Auxiliary Space: O(|S|)

1 ≤ |S| ≤ 15  

We are replacing the old Disqus forum with the new Discussions section given below.
Click here to view old Disqus comments.

to report an issue on this page.


We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?


All Submissions

My Submissions:

Login to access your submissions.

Rank The Permutations

Output Window