Update appNew update is available. Click here to update.
sidenav-btnClose
Topic list
Lexicographic Rank of a String
MEDIUM
1 upvotes
Arrays
Topics (Covered in this problem)
Problem solved
Badge
Skill meter
Arrays
-
-
Other topics
Problem solved
Badge
Skill meter
Strings
-
-
Matrices (2D Arrays)
-
-
Linked List
-
-
Sorting
-
-
Binary Search
-
-
Stacks & Queues
-
-
Trees
-
-
Graph
-
-
Dynamic Programming
-
-
Greedy
-
-
Tries
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
userLevel
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

Lexicographic Rank of a String

Contributed by
Deepanshu_1780
Medium
yellow-spark
0/80
Share
1 upvotes

Problem Statement

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.
Detailed explanation ( Input/output format, Notes, Constraints, Images )
Sample Input 1:
2
abc
cba
Sample Output 1:
1
6
Explanation for Sample Test Case 1:
All permutations with string abc in the lexicographical order will be “abc”, “acb”, “bac”, “bca”, “cab”, “cba”.

Test Case 1:
“abc” will have the rank 1.

Test Case 2:
“cba”  will have rank 6.
Sample Input 2:
2
coding
string
Sample Output 2:
100
598
Reset Code
Full screen
Auto
copy-code
Console