Check if it is possible to perform the given Grid Division | Function that returns true if it is possible to divide the grid satisfying the given conditions ; To store the sum of all the cells of the given parts ; If the sum is equal to the total number of cells in the given grid ; Driver code
function isPossible ( arr , p , n , m ) { var sum = 0 ; for ( var i = 0 ; i < p ; i ++ ) sum += arr [ i ] ; if ( sum == ( n * m ) ) return true ; return false ; } var n = 3 , m = 4 ; var arr = [ 6 , 3 , 2 , 1 ] ; var p = arr . length ; if ( isPossible ( arr , p , n , m ) ) document . write ( " " ) ; else document . write ( " " ) ;