Count substrings of same length differing by a single character from two given strings | Function to count the number of subStrings of equal length which differ by a single character ; Stores the count of pairs of subStrings ; Traverse the String s ; Traverse the String t ; Different character ; Increment the answer ; Count equal subStrings from next index ; Increment the count ; Increment q ; Check the condition ; Increment k ; Add q to count ; Decrement z ; Return the readonly count ; Driver Code ; Function Call
function countSubStrings ( s , t ) { let answ = 0 ; for ( let i = 0 ; i < s . length ; i ++ ) { for ( let j = 0 ; j < t . length ; j ++ ) { if ( t [ j ] != s [ i ] ) { answ += 1 ; let k = 1 ; let z = - 1 ; let q = 1 ; while ( j + z >= 0 && 0 <= i + z && s [ i + z ] == t [ j + z ] ) { z -= 1 ; answ += 1 ; q += 1 ; } while ( s . length > i + k && j + k < t . length && s [ i + k ] == t [ j + k ] ) { k += 1 ; answ += q ; z = - 1 ; } } } } return answ ; } let S = " " ; let T = " " ; document . write ( countSubStrings ( S , T ) ) ;