Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Russian Doll Envelopes

XPChallenge Points: 30
levelLevel: Hard

You are given a 2-D integer array boxes where each element is [w, h] representing the width and height of a box.
A box A can fit inside box B only if both the width and height of A are strictly smaller than those of B.
Find the maximum number of boxes you can nest one inside another.
(Note: Boxes cannot be rotated.)

Example 1:

Input: boxes = [[4,5],[7,6],[8,9],[3,4]]

Output: 3

Explanation:

One optimal nesting is [3,4] → [4,5] → [8,9], giving a chain of length 3.

Example 2:

Input: boxes = [[2,2],[2,2],[2,2]]

Output: 1

Explanation:

All boxes are identical, so only one can be chosen.

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result