Maximum sum and product of the M consecutive digits in a number | Function to find the maximum product ; Driver code
function maxProductSum ( str , m ) { let n = str . length ; let maxProd = Number . MIN_VALUE , maxSum = Number . MIN_VALUE ; for ( let i = 0 ; i <= n - m ; i ++ ) { let product = 1 , sum = 0 ; for ( let j = i ; j < m + i ; j ++ ) { product = product * ( str [ j ] - ' ' ) ; sum = sum + ( str [ j ] - ' ' ) ; } maxProd = Math . max ( maxProd , product ) ; maxSum = Math . max ( maxSum , sum ) ; } document . write ( " " + maxProd + " " ) ; document . write ( " " + maxSum ) ; } let str = " " ; let m = 3 ; maxProductSum ( str , m ) ;