Russian Doll Envelopes

Hard · Dynamic Programming · about 30 minutes

Asked at Google, Amazon, Microsoft, Meta.

Each envelope is given as [w, h]. An envelope can go inside another only if it is strictly narrower and strictly shorter; you can't rotate them. What is the longest chain of envelopes you can nest one inside the next?

Related guides