A utility function to find maximum in arr [ l . . h ]
function max ( arr , l , h ) { var mx = arr [ l ] ; for ( i = l + 1 ; i <= h ; i ++ ) { if ( mx < arr [ i ] ) { mx = arr [ i ] ; } } return parseInt ( mx ) ; }