Minimum number of chairs required to ensure that every worker is seated at any instant | 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 ; Given String ; Function call to find the minimum number of chairs
function findMinimumChairs ( s ) { var count = 0 ; var i = 0 ; var mini = - 2147483647 ; while ( i < s . length ) { if ( s [ i ] == ' ' ) count ++ ; else count -- ; mini = Math . max ( count , mini ) ; i ++ ; } return mini ; } var s = " " ; document . write ( findMinimumChairs ( s ) ) ;