Lexicographic Permutation Rank
Ninja got holiday homework from his English teacher. His teacher gave him a string and told him to find the rank of the string if the string is sorted in lexicographical order.
Ninja is very new into programming, he didn’t know how to solve this question but he has to solve this question as this question has a very heavy weightage among all the questions given in holiday homework.
Ninja knows that you are a very good programmer who has practiced a lot of questions. Help Ninja!.
Note:
There will only be distinct characters in the given string.
Input Format:
First line contains an integer ‘T’ denoting the number of test cases.
First and the only line of the test case contains a string ‘S’.
Output Format:
Output contains an integer ‘X’ denoting the Lexicographic Permutation Rank of the given string.
Note:
You don’t need to print anything, it has already been taken care of. Just implement the given function.
Constraints:
1 <= T <= 25
1 <= |S| <= 20
‘a’ <= S[i] <= ‘z’
Time Limit: 1 sec.
CodingNinjas
author
2y
Permutations
Permutation :
- Let the given string be “CODING”. In the input string, ‘C’ is the first character. There are a total of 6 characters and 0 of them are smaller than ‘C’. So there can be 0 * 5!...read more
CodingNinjas
author
2y
Optimised Approach
The idea is to store the count of smaller elements in the right of each character in an auxiliary array in which the value at every index contains the count of smaller characters in ...read more
Help your peers!
Add answer anonymously...
Top Nutanix Mts1 interview questions & answers
Popular interview questions of Mts1
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app