PROBLEM LINK:Author: Ayush Nagal DIFFICULTY:MEDIUM PREREQUISITES:Math PROBLEM:Given a string $S$, find the rank of the string amongst its permutations sorted lexicographically. Assume that no characters are repeated. EXPLANATION:It is a wellknown problem of Permutation and Combination. First of all, we need an auxiliary array (like Counting Sort) to store the frequency of all the characters in the given string. It can be obtained as follows:
After obtaining the auxiliary array, we can use the following code to obtain the rank:
The rank will be $ans+1$. AUTHOR'S SOLUTION:Author's solution can be found here.
This question is marked "community wiki".
asked 08 Mar, 14:08
