Draft
Timed queue
Description:
You will be given an array of Task
s and queue size
. Tasks go to queue to be done.
Task has the following interface:
interface Task {
value: number,
timeout: number,
}
Fulfilling a Task
means to take its value
and put it to the resulting array after the task's timeout
.
The Task
might be done only if it is taken to the queue (i.e. time passes only for queued tasks).
(!) There should be no more than size
tasks at the same time in the queue.
When the task is done, the next task takes his place in the queue (without delay). In case of timing parity, return the values according to the order in the queue.
Return the resulting array.
EXAMPLE
For input parameters:
tasks = [
{value: 1, timeout: 50 },
{value: 2, timeout: 100 },
{value: 3, timeout: 70 },
{value: 4, timeout: 10 },
{value: 5, timeout: 200 }
];
size = 3;
The process would be:
- 3 first tasks are taken to queue.
- Task with value of
1
will be done first because it requires at least time units (50). After this task, task with value 4 will take his place. - Task with value 4 requires only 10 time units and it is still less then other tasks in queue need (100 - 50 = 50 for the second Task, and 70 - 50 = 20 for the third). So it will be finished next and task with value 5 will take his place.
- At this point, all
Task
s were queued, so we wait until they are done.
The resulting array would be:
[1, 4, 3, 2, 5]
Similar Kata:
Stats:
Created | Feb 9, 2024 |
Warriors Trained | 4 |
Total Skips | 0 |
Total Code Submissions | 4 |
Total Times Completed | 1 |
JavaScript Completions | 1 |
Total Stars | 0 |
% of votes with a positive feedback rating | 0% of 0 |
Total "Very Satisfied" Votes | 0 |
Total "Somewhat Satisfied" Votes | 0 |
Total "Not Satisfied" Votes | 0 |