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...
Nutanix Mts1 interview questions & answers
A Mts1 was asked Q. Ninja and Stack of Boxes Problem Help Ninja to create the tallest stack possible...read more
A Mts1 was asked Q. Split the String Problem Statement You are given a string str consisting of N lo...read more
A Mts1 was asked Q. Lexicographic Permutation Rank Problem Statement Given a distinct string, determ...read more
Popular interview questions of Mts1
A Mts1 was asked Q1. Ninja and Stack of Boxes Problem Help Ninja to create the tallest stack possible...read more
A Mts1 was asked Q2. Split the String Problem Statement You are given a string str consisting of N lo...read more
A Mts1 was asked Q3. Lexicographic Permutation Rank Problem Statement Given a distinct string, determ...read more
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

