Learn
Practice
Newsletter
Resources
F
Toggle theme
0
F
Toggle theme
0
Toggle menu
← Back to All Animations
Sort Items by Groups Respecting Dependencies
Bookmark
Input
LeetCode Example 1
Simple Groups
Custom
n
=
8
,
m
=
2
,
group
=
[-1, -1, 1, 0, 0, 1, 0, -1]
,
beforeItems
=
[[],[6],[5],[6],[3,6],[],[],[]]
0
1
2
3
4
5
6
7
Group Assignments:
-1
0
-1
1
G1
2
G0
3
G0
4
G1
5
G0
6
-1
7
Group Queue:
Result:
Legend:
Default
Processing
Active Group
Visited
algo
master
.
io
Step:
Start: 8 items, 2 initial groups. Assign groups, then topological sort.
0 / 34
Input
LeetCode Example 1
Simple Groups
Custom
n
=
8
,
m
=
2
,
group
=
[-1, -1, 1, 0, 0, 1, 0, -1]
,
beforeItems
=
[[],[6],[5],[6],[3,6],[],[],[]]
0 / 34
0
1
2
3
4
5
6
7
Group Assignments:
-1
0
-1
1
G1
2
G0
3
G0
4
G1
5
G0
6
-1
7
Group Queue:
Result:
Legend:
Default
Processing
Active Group
Visited
algo
master
.
io
Step:
Start: 8 items, 2 initial groups. Assign groups, then topological sort.