Maximum sum and product of the M consecutive digits in a number | Function to find the maximum product ; Driver code
< ? php function maxProductSum ( $ str , $ m ) { $ n = strlen ( $ str ) ; $ maxProd = PHP_INT_MIN ; $ maxSum = PHP_INT_MIN ; for ( $ i = 0 ; $ i <= ( $ n - $ m ) ; $ i ++ ) { $ product = 1 ; $ sum = 0 ; for ( $ j = $ i ; $ j < ( $ m + $ i ) ; $ j ++ ) { $ product = $ product * ( $ str [ $ j ] - '0' ) ; $ sum = $ sum + ( $ str [ $ j ] - '0' ) ; } $ maxProd = max ( $ maxProd , $ product ) ; $ maxSum = max ( $ maxSum , $ sum ) ; } echo " Maximum ▁ Product ▁ = ▁ " , $ maxProd ; echo " Maximum Sum = " } $ str = "3605356297" ; $ m = 3 ; maxProductSum ( $ str , $ m ) ; ? >