Rank The Permutations
Medium Accuracy: 33.83% Submissions: 1127 Points: 4

Given a string, find the rank of the string amongst its permutations sorted lexicographically. 
Return 0 if the characters are repeated in the string.


Example 1:

Input:
S = "abc"
Output:
1
Explanation:
The order permutations with letters 
'a', 'c', and 'b' : 
abc
acb
bac
bca
cab
cba

Example 2:

Input:
S = "acb"
Output:
2


Your Task:
You don't need to read input or print anything. Your task is to complete the function findRank() which takes the string S as input parameter and returns the rank of the string amongst its permutations.

This function returns 0 if the characters are repeated in the string.


Expected Time Complexity: O(|S|*26)
Expected Auxiliary Space: O(|S|)

Note: |S| represents the length of string S.


Constraints:
1 ≤ |S| ≤ 18

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.

Editorial

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

Yes

All Submissions

My Submissions:

Login to access your submissions.

Rank The Permutations

Output Window