Asked inNutanix,Mts1

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.
Be the first one to answer
Add answer anonymously...
Nutanix Mts1 Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter