FastPrepFastPrep
Problem Brief

Chairs Requirement

INTERNNEW GRADOA

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.

1Example 1

Input
simulation = ["CRUL"]
Output
[1]
Explanation
Example 1 illustration
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

    Limits and guarantees your solution can rely on.

    1 ≤ n ≤ 100
    1 ≤ length of each simulation[i] ≤ 10000
    public int[] minChair(String[] simulation) {
      // write your code here
    }
    
    Input

    simulation

    ["CRUL"]

    Output

    [1]

    Sign in to submit your solution.