Minimum number of chairs required to ensure that every worker is seated at any instant | Java program for 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
import java . io . * ; import java . util . * ; class GFG { static int findMinimumChairs ( String s ) { int count = 0 ; int i = 0 ; int mini = Integer . MIN_VALUE ; while ( i < s . length ( ) ) { if ( s . charAt ( i ) == ' E ' ) count ++ ; else count -- ; mini = Math . max ( count , mini ) ; i ++ ; } return mini ; } public static void main ( String [ ] args ) { String s = " EELEE " ; System . out . print ( findMinimumChairs ( s ) ) ; } }