Minimum rooms for m events of n batches with given schedule | java program to find the minimum number of rooms required ; 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
class GFG { static int findMinRooms ( String slots [ ] , int n , int m ) { int counts [ ] = new int [ m ] ; for ( int i = 0 ; i < m ; i ++ ) counts [ i ] = 0 ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = 0 ; j < m ; j ++ ) if ( slots [ i ] . charAt ( j ) == '1' ) counts [ j ] ++ ; int max = - 1 ; for ( int i = 0 ; i < m ; i ++ ) if ( max < counts [ i ] ) max = counts [ i ] ; return max ; } public static void main ( String args [ ] ) { int n = 3 , m = 7 ; String slots [ ] = { "0101011" , "0011001" , "0110111" } ; System . out . println ( findMinRooms ( slots , n , m ) ) ; } }