Count of three non | Function that returns true if s [ i ... j ] + s [ k ... l ] + s [ p ... q ] is a palindrome ; Function to return the count of valid sub - strings ; To store the count of required sub - strings ; For choosing the first sub - string ; For choosing the second sub - string ; For choosing the third sub - string ; Check if the concatenation is a palindrome ; Driver code
function isPalin ( i , j , k , l , p , q , s ) { var start = i , end = q ; while ( start < end ) { if ( s [ start ] != s [ end ] ) return false ; start ++ ; if ( start == j + 1 ) start = k ; end -- ; if ( end == p - 1 ) end = l ; } return true ; } function countSubStr ( s ) { var count = 0 ; var n = s . length ; for ( var i = 0 ; i < n - 2 ; i ++ ) { for ( var j = i ; j < n - 2 ; j ++ ) { for ( var k = j + 1 ; k < n - 1 ; k ++ ) { for ( var l = k ; l < n - 1 ; l ++ ) { for ( var p = l + 1 ; p < n ; p ++ ) { for ( var q = p ; q < n ; q ++ ) { if ( isPalin ( i , j , k , l , p , q , s ) ) { count ++ ; } } } } } } } return count ; } var s = " " ; document . write ( countSubStr ( s ) ) ;