Find the Substring with maximum product | Function to return the value of a character ; Function to find the maximum product subString ; To store subStrings ; Check if current product is maximum possible or not ; If product is 0 ; Return the subString with maximum product ; Driver Code ; Function call
function value ( x ) { return ( x . charCodeAt ( ) - ' ' . charCodeAt ( ) ) ; } function maximumProduct ( str , n ) { let answer = " " , curr = " " ; let maxProduct = 0 , product = 1 ; for ( let i = 0 ; i < n ; i ++ ) { product *= ( 1 * value ( str [ i ] ) ) ; curr += str [ i ] ; if ( product >= maxProduct ) { maxProduct = product ; answer = curr ; } if ( product == 0 ) { product = 1 ; curr = " " ; } } return answer ; } let str = " " ; let n = str . length ; document . write ( maximumProduct ( str , n ) + " " ) ;