Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Queue Reconstruction by Height
Bookmark
Brute Force
Greedy
Segment Tree
Input
Example 1
Example 2
Large
Small
Custom
people
=
[[7,0],[4,4],[7,1],[5,0],[6,1],[5,2]]
people
input
queue
candidate
0
0
1
1
2
2
3
3
4
4
5
5
7
0
4
4
7
1
5
0
6
1
5
2
people
input
queue
candidate
0
0
1
1
2
2
3
3
4
4
5
5
7
0
4
4
7
1
5
0
6
1
5
2
people
input
queue
candidate
0
0
1
1
2
2
3
3
4
4
5
5
7
0
4
4
7
1
5
0
6
1
5
2
7
0
7
1
5
2
4
4
5
0
6
1
ordering
43
: fails at index
3
→ next permutation
people
input
queue
candidate
0
0
1
1
2
2
3
3
4
4
5
5
7
0
4
4
7
1
5
0
6
1
5
2
7
0
6
1
5
0
4
4
5
2
7
1
ordering
86
: fails at index
2
→ next permutation
people
input
queue
candidate
0
0
1
1
2
2
3
3
4
4
5
5
7
0
4
4
7
1
5
0
6
1
5
2
4
4
7
0
5
0
6
1
5
2
7
1
ordering
130
: fails at index
0
→ next permutation
people
input
queue
candidate
0
0
1
1
2
2
3
3
4
4
5
5
7
0
4
4
7
1
5
0
6
1
5
2
4
4
5
0
7
0
5
2
7
1
6
1
ordering
173
: fails at index
0
→ next permutation
people
input
queue
candidate
0
0
1
1
2
2
3
3
4
4
5
5
7
0
4
4
7
1
5
0
6
1
5
2
4
4
5
2
7
0
7
1
5
0
6
1
ordering
217
: fails at index
0
→ next permutation
people
input
queue
candidate
0
0
1
1
2
2
3
3
4
4
5
5
7
0
4
4
7
1
5
0
6
1
5
2
7
1
7
0
5
2
4
4
6
1
5
0
ordering
260
: fails at index
0
→ next permutation
people
input
queue
candidate
0
0
1
1
2
2
3
3
4
4
5
5
7
0
4
4
7
1
5
0
6
1
5
2
7
1
5
0
6
1
4
4
5
2
7
0
ordering
304
: fails at index
0
→ next permutation
people
input
queue
candidate
0
0
1
1
2
2
3
3
4
4
5
5
7
0
4
4
7
1
5
0
6
1
5
2
7
1
5
2
4
4
6
1
7
0
5
0
ordering
347
: fails at index
0
→ next permutation
people
input
queue
candidate
0
0
1
1
2
2
3
3
4
4
5
5
7
0
4
4
7
1
5
0
6
1
5
2
5
0
7
0
5
2
6
1
4
4
7
1
Queue reconstructed!
algo
master
.
io
Step:
Start: try every ordering of the people until one satisfies every k.
0 / 392
Input
Example 1
Example 2
Large
Small
Custom
people
=
[[7,0],[4,4],[7,1],[5,0],[6,1],[5,2]]
0 / 392
algo
master
.
io
Step:
Start: try every ordering of the people until one satisfies every k.