Interview Question

Comment hidden because of low score. Click to expand.
1
of 1 vote

This is a dynamic programming question. First sort the boxes in descending order of area in O(n log n). Then for each box i, the maximum stack height is:

H(i) = Max (H(i-1), H(j) + h(i)) where L(i) < L(j) and W(i) < W(j)

FInally just pick the max height looking back from the array values.

Comment hidden because of low score. Click to expand.
0
of 0 vote

@Ashish lets consider boxes of dimensions below. Can you explain how will it work

box 1->5,4,2
box 2->5,3,1
box 3->8,6,3

Comment hidden because of low score. Click to expand.
0
of 0 vote

@ ashish instead of comparing both L and W just compare the area since it is possible L1<L2 and W1>W2 still area1 >area2

Comment hidden because of low score. Click to expand.
0
of 0 vote

Check the box stacking problem - people.csail.mit.edu/bdean/6.046/dp/.

Comment hidden because of low score. Click to expand.
0
of 0 vote

@eepiyush: Why spam CC with OLD posts only.
Go to stackoverflow, and post there, your moron!

This problem I saw in GOOGLE section. I found "lol" presented a complete solution to this. Why the fucking asshole you need to repost... if you can't get the solution, why don't ask it there!

Comment hidden because of low score. Click to expand.
0

Didn't wish to comment. But your constantly rude and uncouth remarks irritate far more than seeing a question being repeated

Comment hidden because of low score. Click to expand.
0
of 0 vote

Guys, this is NOT a duplicate question.

All the solutions above work only when using multiple (duplicate) instances of a box are allowed. However, @eepiyush has clearly mentioned that "you can use each box only once"

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.