Problem · Queue

Queue Check-in Simulation with Capacity Limit

EasyCapital OneFULLTIMEOA

Complete the function below. The function receives the full standard input as a single string and must return the exact standard output lines for the described problem.

There is a single check-in line. You are given an integer array arrivalTimes where arrivalTimes[i] is the time (in seconds) when person i arrives at the end of the line.

Rules:

  • Only one person is processed at a time. The person at the front of the line takes 30 seconds to check in.
  • When a person arrives, if the number of people currently waiting or being served in the system is strictly greater than 10 (i.e., the system already contains more than 10 people), that person leaves immediately and will not check in.
  • arrivalTimes is non-decreasing; persons arriving at the same time are enqueued in input order.

Return an array result where:

  • If person i is served, result[i] is the time they start service.
  • If person i leaves due to capacity, result[i] is represented as the literal string null in the output.

Input format: The first line contains an integer n (the number of people). The second line contains n space-separated integers representing arrivalTimes.

Output format: A single line containing the space-separated entries of result, where each entry is either an integer (start service time) or the literal token null (for persons who left due to capacity).

Examples
01 · Example 1
input = "3\n0 0 0"
return = 0 30 60
3 people all arrive at time 0. Person 0 starts service immediately at time 0. Person 1 waits and starts at time 30. Person 2 starts at time 60. The system never exceeds capacity, so result = [0, 30, 60].
Constraints

  • 1 <= n <= 2 × 105
  • 0 <= arrivalTimes[i] <= 109
  • arrivalTimes is non-decreasing.
  • A person leaves immediately (result is null) if, at the moment of their arrival, the number of people already in the system (waiting or currently being served) is strictly greater than 10.
  • The literal string null (lowercase) is used in the output to represent a person who left due to capacity.

More Capital One problems
drafts saved locally
public String[] solveOneQueueCheckInSimulation(String input) {
    // write your code here
}
input"3\n0 0 0"
expected["0 30 60"]
checking account