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:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- 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)
- Number of ways to insert two pairs of parentheses into a string of N characters
- Find the number of pairs such that their gcd is equals to 1
- Find number of pairs (x, y) in an Array such that x^y > y^x | Set 2
- Find the number of ordered pairs such that a * p + b * q = N, where p and q are primes
- 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 length of factorial of a number in any given base
- Find Nth even length palindromic number formed using digits X and Y
- Find the number of valid parentheses expressions of given length
- Construct a string of length L such that each substring of length X has exactly Y distinct letters
- Program to find Length of Bridge using Speed and Length of Train
- Find the length of the median of a Triangle if length of sides are given
- Number of ways to cut a stick of length N into in even length at most K units long pieces
- Minimize number of cuts required to break N length stick into N unit length sticks
- Maximize product of digit sum of consecutive pairs in a subsequence of length K
- 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