Recursively break a number in 3 parts to get maximum sum | Function to find the maximum sum ; base conditions ; recursively break the number and return what maximum you can get ; Driver program to test the above function
function breakSum ( n ) { if ( n == 0 n == 1 ) return n ; return Math . max ( ( breakSum ( Math . floor ( n / 2 ) ) + breakSum ( Math . floor ( n / 3 ) ) + breakSum ( Math . floor ( n / 4 ) ) ) , n ) ; } let n = 12 ; document . write ( breakSum ( n ) ) ;