Ninja and Stack of Boxes Problem
Help Ninja to create the tallest stack possible using given 3-D boxes with dimensions Length 'L', Breadth 'B', and Height 'H'. Each box can be rotated to use any side as the base, but you can only stack a box on another if the lower box's 2-D base dimensions both exceed those of the higher box. Multiple instances of any box can be used.
Input:
The first line contains an integer 'T' indicating the number of test cases.
For each test case, first line contains an integer 'N' representing the number of boxes.
Next, 'N' lines follow, each containing three space-separated integers 'L', 'B', and 'H' representing the dimensions of each box.
Output:
For each test case, output the maximum possible height of the stack.
Each test case should be output on a separate line.
Example:
Input:
2
1
2 1 2
2
1 2 3
2 1 3
Output:
2
6
Constraints:
- 1 <= T <= 100
- 1 <= N <= 5000
- 1 <= L, B, H <= 100000
Note:
You do not need to print anything; just implement the function.

AnswerBot
4mo
Implement a function to find the maximum possible height of a stack of boxes given their dimensions.
Create all possible rotations of each box to consider all orientations for stacking
Sort the boxes ba...read more
Help your peers!
Add answer anonymously...
Top Mts1 Interview Questions Asked at Nutanix
Q. Split the String Problem Statement You are given a string str consisting of N lo...read more
Q. Lexicographic Permutation Rank Problem Statement Given a distinct string, determ...read more
Q. What are effective paging techniques, and how do you count page faults?
Interview Questions Asked to Mts1 at Other Companies
Top Skill-Based Questions for Nutanix Mts1
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Operating Systems Interview Questions and Answers
250 Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

