human
Count of same length Strings that exists lexicographically in between two given Strings | Function to find the count of strings less than given string lexicographically.
Find length of string s.
Looping over the string characters and finding strings less than that character.
Function to find the count of same length Strings that exists lexicographically in between two given Strings.
Count string less than S1.
Count string less than S2.
Total strings between S1 and S2 would be difference between the counts - 1.
If S1 is lexicographically greater than S2 then return 0 , otherwise return the value of totalString.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to count of same length Strings that exists lexicographically in between two given Strings and the other steps required.
 def LexicoLesserStrings ( s ) :
	count = 0
	length = len ( s )
	for i in range ( length ) :
		count += ( ( ord ( s [ i ] ) - ord ( ' a ' ) ) * pow ( 26 , length - i - 1 ) )
	return count
def countString ( S1 , S2 ) :
	countS1 = LexicoLesserStrings ( S1 )
	countS2 = LexicoLesserStrings ( S2 )
	totalString = countS2 - countS1 - 1 ;
	return ( 0 if totalString < 0 else totalString )
S1 = " cda " ;
S2 = " cef " ;
print ( countString ( S1 , S2 ) )