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
function LexicoLesserStrings ( s ) { var count = 0 ; var len ; len = s . length ; for ( var i = 0 ; i < len ; i ++ ) { count += ( s [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ) * Math . pow ( 26 , len - i - 1 ) ; } return count ; } function countString ( S1 , S2 ) { var countS1 , countS2 , totalString ; countS1 = LexicoLesserStrings ( S1 ) ; countS2 = LexicoLesserStrings ( S2 ) ; totalString = countS2 - countS1 - 1 ; return totalString < 0 ? 0 : totalString ; } var S1 , S2 ; S1 = " " ; S2 = " " ; document . write ( countString ( S1 , S2 ) ) ;