Minimum rooms for m events of n batches with given schedule | Returns minimum number of rooms required to perform classes of n groups in m slots with given schedule . ; Store number of class happening in empty slot ; initialize all values to zero ; Number of rooms required is equal to maximum classes happening in a particular slot . ; driver code
function findMinRooms ( slots , n , m ) { let counts = Array ( m ) . fill ( 0 ) ; for ( let i = 0 ; i < m ; i ++ ) counts [ i ] = 0 ; for ( let i = 0 ; i < n ; i ++ ) for ( let j = 0 ; j < m ; j ++ ) if ( slots [ i ] [ j ] == ' ' ) counts [ j ] ++ ; let max = - 1 ; for ( let i = 0 ; i < m ; i ++ ) if ( max < counts [ i ] ) max = counts [ i ] ; return max ; } let n = 3 , m = 7 ; let slots = [ " " , " " , " " ] ; document . write ( findMinRooms ( slots , n , m ) ) ;