Count of bitonic substrings from the given string | Function to find all the bitonic sub strings ; Pick starting point ; Iterate till length of the string ; Pick ending point for string ; Substring from i to j is obtained ; Substrings of length 1 ; Increase count ; For increasing sequence ; Check for strictly increasing ; Increase count ; Check for decreasing sequence ; Increase count ; Print the result ; Given string ; Function Call
function subString ( str , n ) { var c = 0 ; for ( var len = 1 ; len <= n ; len ++ ) { for ( var i = 0 ; i <= n - len ; i ++ ) { var j = i + len - 1 ; var temp = str [ i ] , f = 0 ; if ( j == i ) { c ++ ; continue ; } var k = i + 1 ; while ( temp < str [ k ] && k <= j ) { temp = str [ k ] ; k ++ ; f = 2 ; } if ( k > j ) { c ++ ; f = 2 ; } while ( temp > str [ k ] && k <= j && f != 2 ) { k ++ ; f = 0 ; } if ( k > j && f != 2 ) { c ++ ; f = 0 ; } } } document . write ( c ) ; } var str = " " . split ( ' ' ) ; subString ( str , str . length ) ;