text: Number of substrings that start with " geeks " and end with " for " | Function to return the count of required substrings ; For every index of the string ; If the substring starting at the current index is " geeks " ; If the substring is " for " ; Driver code
code: function countSubStr ( s , n ) { var c1 = 0 , c2 = 0 ; for ( var i = 0 ; i < n ; i ++ ) { if ( s . substring ( i , i + 5 ) == " " ) c1 ++ ; if ( s . substring ( i , i + 3 ) == " " ) c2 = c2 + c1 ; } return c2 ; } var s = " " ; var n = s . length ; document . write ( countSubStr ( s , n ) ) ;