Question bank › Greedy
Dsa Greedy Hard

Gift Wrapping of Boxes

You are given a collection of boxes, each with a specified width and height. To wrap gifts efficiently, you want to maximize the number of boxes that can be wrapped together, but no box can be placed on another unless both the width and height of the box being placed are strictly smaller than those of the box below it. Given the dimensions of the boxes, calculate the maximum number of boxes you can stack in this manner. Input Format: - The first line contains an integer N (1 <= N <= 1000), the number of boxes. - The following N lines each contain two integers: width and height of the boxes (1 <= width, height <= 10000). Output Format: - Print a single integer representing the maximum number of boxes that can be stacked. Example: Input: 5 2 3 1 2 3 4 2 2 4 5 Output: 3 In this case, you could stack the boxes with dimensions (1,2) under (2,3) and (3,4) under (4,5) for a maximum of 3 boxes.

Key concepts

greedysortingcombinatorics

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.