Minimum number of chairs required to ensure that every worker is seated at any instant | C ++ implementation of the above approach ; Function to find the minimum number of chairs required to ensure that every worker is seated at any time ; Stores the number of chairs required ; Pointer to iterate ; Stores minimum number of chairs required ; Iterate over every character ; If character is ' E ' ; Increase the count ; Otherwise ; Update maximum value of count obtained at any given time ; Return mini ; Driver Code ; Given String ; Function call to find the minimum number of chairs
#include <bits/stdc++.h> NEW_LINE using namespace std ; int findMinimumChairs ( string s ) { int count = 0 ; int i = 0 ; int mini = INT_MIN ; while ( i < s . length ( ) ) { if ( s [ i ] == ' E ' ) count ++ ; else count -- ; mini = max ( count , mini ) ; i ++ ; } return mini ; } int main ( ) { string s = " EELEE " ; cout << findMinimumChairs ( s ) ; }