Description
Solutions
Chairs Requirement
🔥 FULLTIME

In this challenge, determine the minimum number of chairs to be purchased to accommodate all workers in a new business workroom. There is no chair at the beginning.

There will be a string array of simulations. Each simulation is described by a combination of four characters: C, R, U, and L

  • C - A new employee arrives in the workroom. If there is a chair available, the employee takes it. Otherwise, a new one is purchased.
  • R - An employee goes to a meeting room, freeing up a chair.
  • U - An employee arrives from a meeting room. If there is a chair available, the employee takes it. Otherwise, a new one is purchased.
  • L - An employee leaves the workroom, freeing up a chair.

Function Description

Complete the minChair function.

minChair has the following parameter(s):

  • string simulation[n]: an array of strings representing discrete simulations to process.

Return

int[n]: an array of integers denoting the minimal number of chairs required for each simulation.

Example 1:

Input:  simulation = ["CRUL"]
Output: [1]
Explanation:
In this case, there is only one simulation, CRUL, represented in the table above.
  • At first, there are 0 chairs.
  • "C": A new employee arrives in the workroom and one chair was purchased.
  • "R": An employee goes to the meeting room, freeing up a chair.
  • "U": An employee arrives from the meeting room, took the chair available.
  • "L": An employee leaves the workroom, freeing up a chair.
  • The minimum number of chairs to be purchased in one chair in this case. Result = [1].
    Constraints:
      1 ≤ n ≤ 100
      1 ≤ length of each simulation[i] ≤ 10000
    Testcase

    Result
    Case 1

    input:

    output: