Check if all objects of type A and B can be placed on N shelves | Function to return if allocation is possible or not ; Stores the shelves needed for items of type - A and type - B ; Find number of shelves needed for items of type - A ; Fill A / K shelves fully by the items of type - A ; Otherwise ; Fill A / L shelves fully and add remaining to an extra shelf ; Find number of shelves needed for items of type - B ; Fill B / L shelves fully by the items of type - B ; Fill B / L shelves fully and add remaining to an an extra shelf ; Total shelves needed ; If required shelves exceed N ; Driver code
function isPossible ( A , B , N , K , L ) { let needa , needb ; if ( A % K == 0 ) needa = Math . floor ( A / K ) ; else needa = Math . floor ( A / K ) + 1 ; if ( B % L == 0 ) needb = Math . floor ( B / L ) ; else needb = Math . floor ( B / L ) + 1 ; let total = needa + needb ; if ( total > N ) return false ; else return true ; } let A = 3 , B = 3 , N = 3 ; let K = 4 , M = 2 ; if ( isPossible ( A , B , N , K , M ) ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ;