Problem · Simulation

Chairs Requirement

Learn this problem
EasyIBMFULLTIMEOA
See IBM hiring insights

Problem statement

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

minChair(simulation: String[]) → int[]

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.

Examples

Example 1

simulation = ["CRUL"]return = [1]
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

    1 ≤ n ≤ 100
    1 ≤ length of each simulation[i] ≤ 10000

    More IBM problems

    drafts saved locally
    public int[] minChair(String[] simulation) {
      // write your code here
    }
    
    simulation["CRUL"]
    expected[1]
    checking account