Russian Doll Envelopes
Try to solve the Russian Doll Envelopes problem.
We'll cover the following
Statement
You are given a 2D array of integers, envelopes
, where each element envelopes[i] = [w
i
, h
i
]
represents the width and height of an envelope. An envelope can fit inside another if and only if its width and height are strictly smaller than the width and height of the other envelope. The task is to determine the maximum number of envelopes that can be nested inside each other, similar to
Constraints:
envelopes.length
envelopes[i].length
w
i
,h
i
Examples
Understand the problem
Let’s take a moment to make sure you’ve correctly understood the problem. The quiz below helps you check if you’re solving the problem correctly:
Russian Doll Envelopes
How many envelopes can be nested into each other in the following input?
envelopes
=
Figure it out!
We have a game for you to play. Rearrange the logical building blocks to better understand how to solve this problem.
Try it yourself
Implement your solution in the following coding playground.
class Solution {public int maxEnvelopes(int[][] envelopes) {// Replace this placeholder return statement with your codereturn -1;}}
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.