Maximum given sized rectangles that can be cut out of a sheet of paper | Function to return the maximum rectangles possible ; Cut rectangles horizontally if possible ; One rectangle is a single cell ; Total rectangles = total cells ; Cut rectangles vertically if possible ; Return the maximum possible rectangles ; Driver Code
function maxRectangles ( L , B , l , b ) { var horizontal = 0 , vertical = 0 ; if ( l <= L && b <= B ) { var columns = parseInt ( B / b ) ; var rows = parseInt ( L / l ) ; horizontal = rows * columns ; } if ( l <= B && b <= L ) { var columns = parseInt ( L / b ) ; var rows = parseInt ( B / l ) ; vertical = rows * columns ; } return Math . max ( horizontal , vertical ) ; } var L = 10 , B = 7 , l = 4 , b = 3 ; document . write ( maxRectangles ( L , B , l , b ) ) ;