A pair of string s and r are called magical if for every index i the character of s is less than r i.e. s[i] < r[i]. The task is to count number of pairs of strings possible of length L. Since this value can be large, give answer modulo 109.
Note: The string contains only lowercase English alphabets.
Input: L = 1
Since the length of the strings required is 1.
If s = “a” then r can be any one of “b”, “c”, “d”, … “z” (25 Possibilities)
If s = “b” then r can be any one of “c”, “d”, “e”, … “z” (24 Possibilities)
If s = “y” then r can only be “z” (1 Possibilities)
s cannot be “z” as it is the maximum lowecase character.
Hence total possibilities are 1 + 2 + 3 + … + 25 = 325
Input: L = 2
Approach: For L = 1, total possibilities are 325. For L = 2, total possibilities are 3252. Total possibilities for any value of L will be 325L. Since this value can be large, print the answer modulo 109.
Below is the implementation of the above approach:
- Find longest length number in a string
- C program to find the length of a string
- Given GCD G and LCM L, find number of possible pairs (a, b)
- Append a digit in the end to make the number equal to the length of the remaining string
- Find the number of distinct pairs of vertices which have a distance of exactly k in a tree
- Find the number of valid parentheses expressions of given length
- Program to find Length of Bridge using Speed and Length of Train
- Find if it is possible to make a binary string which contanins given number of "0", "1" , "01" and "10" as sub sequences
- Count the pairs of vowels in the given string
- Count pairs of characters in a string whose ASCII value difference is K
- Check if the frequency of any character is more than half the length of the string
- Generate all binary strings of length n with sub-string "01" appearing exactly twice
- Smallest length string with repeated replacement of two distinct adjacent
- Find the maximum possible value of a[i] % a[j] over all pairs of i and j
- Find Cube Pairs | Set 1 (A n^(2/3) Solution)
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.