Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Process Tasks Using Servers
Bookmark
Input
Example 1
Example 2
Simple
Custom
servers
=
[3, 3, 2]
,
tasks
=
[1, 2, 3, 2, 1, 2]
1
0
2
1
3
2
2
3
1
4
2
5
S0
3
S1
3
S2
2
each task goes to the lightest free server, ties to the lowest index
1
0
2
1
3
2
2
3
1
4
2
5
S0
3
S1
3
S2
2
each task goes to the lightest free server, ties to the lowest index
t =
0
assigned =
0
/ 6
1
0
2
1
3
2
2
3
1
4
2
5
S0
3
free
S1
3
free
S2
2
free
free (weight, idx):
busy (release t):
S0:3
S1:3
S2:2
ans:
task
0
(duration
1
) arrives at t =
0
t =
1
assigned =
1
/ 6
1
→S2
0
2
1
3
2
2
3
1
4
2
5
S0
3
free
S1
3
free
S2
2
→ t=1
free (weight, idx):
busy (release t):
S0:3
S1:3
S2@1
ans:
2
task
1
(duration
2
) arrives at t =
1
t =
1
assigned =
2
/ 6
1
→S2
0
2
→S2
1
3
2
2
3
1
4
2
5
S0
3
free
S1
3
free
S2
2
→ t=3
free (weight, idx):
busy (release t):
S0:3
S1:3
S2@3
ans:
2
2
lightest free:
S2
(w =
2
) → busy until t =
3
, ans[
1
] =
2
t =
2
assigned =
3
/ 6
1
→S2
0
2
→S2
1
3
→S0
2
2
3
1
4
2
5
S0
3
→ t=5
S1
3
free
S2
2
→ t=3
free (weight, idx):
busy (release t):
S0@5
S1:3
S2@3
ans:
2
2
0
lightest free:
S0
(w =
3
) → busy until t =
5
, ans[
2
] =
0
t =
3
assigned =
3
/ 6
1
→S2
0
2
→S2
1
3
→S0
2
2
3
1
4
2
5
S0
3
→ t=5
S1
3
free
S2
2
→ t=3
free (weight, idx):
busy (release t):
S0@5
S1:3
S2@3
ans:
2
2
0
task
3
(duration
2
) arrives at t =
3
t =
3
assigned =
4
/ 6
1
→S2
0
2
→S2
1
3
→S0
2
2
→S2
3
1
4
2
5
S0
3
→ t=5
S1
3
free
S2
2
→ t=5
free (weight, idx):
busy (release t):
S0@5
S1:3
S2@5
ans:
2
2
0
2
lightest free:
S2
(w =
2
) → busy until t =
5
, ans[
3
] =
2
t =
4
assigned =
5
/ 6
1
→S2
0
2
→S2
1
3
→S0
2
2
→S2
3
1
→S1
4
2
5
S0
3
→ t=5
S1
3
→ t=5
S2
2
→ t=5
free (weight, idx):
busy (release t):
S0@5
S1@5
S2@5
ans:
2
2
0
2
1
lightest free:
S1
(w =
3
) → busy until t =
5
, ans[
4
] =
1
t =
5
assigned =
5
/ 6
1
→S2
0
2
→S2
1
3
→S0
2
2
→S2
3
1
→S1
4
2
5
S0
3
free
S1
3
free
S2
2
free
free (weight, idx):
busy (release t):
S0:3
S1:3
S2:2
ans:
2
2
0
2
1
S2, S0, S1
finished by t =
5
→ back to free
t =
5
assigned =
6
/ 6
1
→S2
0
2
→S2
1
3
→S0
2
2
→S2
3
1
→S1
4
2
→S2
5
S0
3
free
S1
3
free
S2
2
→ t=7
free (weight, idx):
busy (release t):
S0:3
S1:3
S2@7
ans:
2
2
0
2
1
2
ans = [2, 2, 0, 2, 1, 2]
algo
master
.
io
Step:
Start: servers=[3,3,2], tasks=[1,2,3,2,1,2]
0 / 17
Input
Example 1
Example 2
Simple
Custom
servers
=
[3, 3, 2]
,
tasks
=
[1, 2, 3, 2, 1, 2]
0 / 17
algo
master
.
io
Step:
Start: servers=[3,3,2], tasks=[1,2,3,2,1,2]