FastPrepFastPrep
Problem Brief

User Quota Scheduling with Expiring Assignments

FULLTIMEOA

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.

Original prompt

Problem: User Quota Scheduling with Expiring Assignments (Level 3)

Implement a user/task scheduling system.

Requirements

Create user: each user has a quota meaning the maximum number of concurrent assignments allowed for that user. Assign a task: assign to a user a time interval [startTime, endTime) with a taskId.

Rules

Each assignment is active on the half-open interval [startTime, endTime). Once endTime is reached, the assignment expires and no longer counts toward the user’s concurrent quota. Example: existing assignment [4,10) no longer counts for any t >= 10. If adding a new assignment would make the number of concurrent active assignments exceed quota at any time, the assignment must be rejected.

Output

For each assignment attempt, output whether it succeeds (e.g., true/false or OK/FAIL per spec).

Constraints

Potentially large, but OA tests may be small; a straightforward approach may pass. Test ideas quota=1: add [4,10) ok; add [10,12) ok. quota=1: add [4,10) ok; add [9,12) reject. quota=2: adding a third overlapping interval should reject. Edge: zero-length intervals (per spec). Multiple users are independent.

Function Description

Complete solveUserQuotaScheduling. It has one parameter, String input, containing the full stdin payload. Return the stdout payload as an array of lines, without trailing newline characters.

1Example 1

Input
input = "CREATE_USER u1 1\nASSIGN u1 1 4 10\nASSIGN u1 2 10 12"
Output
["OK", "OK"]
Explanation

The returned string must match the expected standard output for the sample input.

Constraints

Limits and guarantees your solution can rely on.

Use the limits and requirements stated in the prompt.

public String[] solveUserQuotaScheduling(String input) {
    // write your code here
}
Input

input

"CREATE_USER u1 1\nASSIGN u1 1 4 10\nASSIGN u1 2 10 12"

Output

["OK", "OK"]

Sign in to submit your solution.