Minimum rooms for m events of n batches with given schedule | CPP program to find minimum number of rooms required ; Returns minimum number of rooms required to perform classes of n groups in m slots with given schedule . ; Store count of classes happening in every slot . ; initialize all values to zero ; Number of rooms required is equal to maximum classes happening in a particular slot . ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int findMinRooms ( string slots [ ] , int n , int m ) { int counts [ m ] = { 0 } ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = 0 ; j < m ; j ++ ) if ( slots [ i ] [ j ] == '1' ) counts [ j ] ++ ; return * max_element ( counts , counts + m ) ; } int main ( ) { int n = 3 , m = 7 ; string slots [ n ] = { "0101011" , "0011001" , "0110111" } ; cout << findMinRooms ( slots , n , m ) ; return 0 ; }