Problem statement
Write function solution(jobs, workers). Inputs and outputs are JSON values. Do not modify input arrays or objects. External libraries, network access, and asynchronous functions are not supported. jobs is an array of {id:string,duration:nonnegative integer}; workers is an integer from 1 to 8. Workers are numbered from 0 and initially available at time 0. Assign jobs in input order to the earliest available worker; break ties by the smallest worker number. Jobs start immediately when that worker is available and are not interrupted. Return {id,worker,start,end} in input order. Zero duration is valid, and duplicate IDs still represent separate jobs. Input limits: at most 50,000 items per input array and 1,000 characters per string. Numbers are finite; integers and accumulated integer results stay in the JavaScript safe-integer range. Other types and validity rules follow the statement above.
Example input and output
Example 1
Function arguments
[
[
{
"id": "a",
"duration": 3
},
{
"id": "b",
"duration": 1
},
{
"id": "c",
"duration": 2
}
],
2
]Return value
[
{
"id": "a",
"worker": 0,
"start": 0,
"end": 3
},
{
"id": "b",
"worker": 1,
"start": 0,
"end": 1
},
{
"id": "c",
"worker": 1,
"start": 1,
"end": 3
}
]Example 2
Function arguments
[
[
{
"id": "a",
"duration": 1
},
{
"id": "b",
"duration": 2
}
],
1
]Return value
[
{
"id": "a",
"worker": 0,
"start": 0,
"end": 1
},
{
"id": "b",
"worker": 0,
"start": 1,
"end": 3
}
]Example 3
Function arguments
[
[
{
"id": "a",
"duration": 1
},
{
"id": "b",
"duration": 1
},
{
"id": "c",
"duration": 1
},
{
"id": "d",
"duration": 1
}
],
2
]Return value
[
{
"id": "a",
"worker": 0,
"start": 0,
"end": 1
},
{
"id": "b",
"worker": 1,
"start": 0,
"end": 1
},
{
"id": "c",
"worker": 0,
"start": 1,
"end": 2
},
{
"id": "d",
"worker": 1,
"start": 1,
"end": 2
}
]