Given a binary string , count number of substrings that start and end with 1. | A O ( n ) javascript program to count number of substrings starting and ending with 1 ; Traverse input string and count of 1 's in it ; Return count of possible pairs among m 1 's ; Driver program to test the above function
function countSubStr ( str , n ) { for ( let i = 0 ; i < n ; i ++ ) { if ( str [ i ] == ' ' ) m ++ ; } return m * Math . floor ( ( m - 1 ) / 2 ) ; } let str = " " ; let n = str . length ; document . write ( countSubStr ( str , n ) ) ;