Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Russian Doll Envelopes
Bookmark
Dynamic Programming
Sort + Binary Search
Input
Example 1
Example 2
Example 3
Custom
envelopes
=
[[5,4],[6,4],[6,7],[2,3]]
envelopes sorted by width, then height
i = -
j = -
maxLen = -
envelopes sorted by width, then height
i = -
j = -
maxLen = -
envelopes sorted by width, then height
2x3
0
dp 1
5x4
1
dp 1
6x4
2
dp 1
6x7
3
dp 1
i
i = 1
j = -
maxLen = 1
envelopes sorted by width, then height
2x3
0
dp 1
5x4
1
dp 2
6x4
2
dp 1
6x7
3
dp 1
i
j
i = 1
j = 0
maxLen = 1
envelopes sorted by width, then height
2x3
0
dp 1
5x4
1
dp 2
6x4
2
dp 1
6x7
3
dp 1
i
i = 2
j = -
maxLen = 2
envelopes sorted by width, then height
2x3
0
dp 1
5x4
1
dp 2
6x4
2
dp 2
6x7
3
dp 1
i
j
i = 2
j = 0
maxLen = 2
envelopes sorted by width, then height
2x3
0
dp 1
5x4
1
dp 2
6x4
2
dp 2
6x7
3
dp 1
i
i = 2
j = -
maxLen = 2
envelopes sorted by width, then height
2x3
0
dp 1
5x4
1
dp 2
6x4
2
dp 2
6x7
3
dp 1
i
j
i = 3
j = 0
maxLen = 2
envelopes sorted by width, then height
2x3
0
dp 1
5x4
1
dp 2
6x4
2
dp 2
6x7
3
dp 2
i
j
i = 3
j = 1
maxLen = 2
envelopes sorted by width, then height
2x3
0
dp 1
5x4
1
dp 2
6x4
2
dp 2
6x7
3
dp 3
i
j
i = 3
j = 2
maxLen = 2
envelopes sorted by width, then height
2x3
0
dp 1
5x4
1
dp 2
6x4
2
dp 2
6x7
3
dp 3
i = -
j = -
maxLen = 3
algo
master
.
io
Step:
Nest envelopes: each must fit strictly inside the next (both width AND height larger)
0 / 25
Input
Example 1
Example 2
Example 3
Custom
envelopes
=
[[5,4],[6,4],[6,7],[2,3]]
0 / 25
algo
master
.
io
Step:
Nest envelopes: each must fit strictly inside the next (both width AND height larger)