763. Maximum Nested Boxes

You are provided with a 2D array of integers called boxes, where boxes[i] = [ widthi, heighti ] represents the width and height of a specific box.

A box can be placed (nested) inside another box if and only if both the width and the height of the inner box are strictly smaller than the width and height of the outer box.

Determine the maximum number of boxes you can nest inside one another.

Note: You are not allowed to rotate the boxes.

Example 1:

Input: boxes = [[4, 5], [4, 6], [6, 7], [2, 3], [1, 1]]

Output : 4

Explanation:

The optimal nesting sequence is [1, 1] -> [2, 3] -> [4, 5] -> [6, 7], giving a maximum of 4 boxes.

Example 2:

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

Output : 1

Explanation: Dimensions must be strictly smaller. Identical boxes cannot be nested, so we can only select 1 box.

Now Your Turn!

Pick the correct output for the given input

Input : boxes = [[1, 3], [3, 5], [6, 8], [6, 7], [8, 10]]

(Determine the maximum number of boxes you can nest one inside the other)

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= boxes.length <= 105
  • boxes[i].length == 2
  • 1 <= [ widthi heighti ] <= 105

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

Fun Facts

0
class Solution {
public:
int maxBoxes(vector<vector<int>>& boxes) {
// Write your code here
}
};
Test Case

Input:

Boxes