For the best experience, increase the window size or view on a laptop or desktop device
Title | ||
|---|---|---|
Loading... | ||
For the best experience, increase the window size or view on a laptop or desktop device
Title | ||
|---|---|---|
Loading... | ||
Given a string array where each string consists of the characters 'C', 'U', 'L', 'R':
'C' indicates a new employee has joined and needs a chair.
'U' indicates an employee has gone into a meeting room, freeing up a chair.
'L' indicates an employee has come out of a meeting room and needs a chair.
'R' indicates an employee has left the company, freeing up a chair.
(Note: The letters and their corresponding actions might be mixed up, but these are the four scenarios.)
For each case, if the current number of spare chairs is not enough to meet the demand, a new chair needs to be purchased (e.g., if the first letter is 'C', it means a new employee has arrived, but there are no available chairs at the moment, assuming initially there are zero chairs, then a new chair must be purchased). The task is to calculate the minimum number of chairs that need to be bought for each string and output an integer array. This question is straightforward; just iterate through the string once.
Given a string array where each string consists of the characters 'C', 'U', 'L', 'R':
'C' indicates a new employee has joined and needs a chair.
'U' indicates an employee has gone into a meeting room, freeing up a chair.
'L' indicates an employee has come out of a meeting room and needs a chair.
'R' indicates an employee has left the company, freeing up a chair.
(Note: The letters and their corresponding actions might be mixed up, but these are the four scenarios.)
For each case, if the current number of spare chairs is not enough to meet the demand, a new chair needs to be purchased (e.g., if the first letter is 'C', it means a new employee has arrived, but there are no available chairs at the moment, assuming initially there are zero chairs, then a new chair must be purchased). The task is to calculate the minimum number of chairs that need to be bought for each string and output an integer array. This question is straightforward; just iterate through the string once.
Output