How to Solve This Type of Problem..
There is a room where boxes are stacked. If the room is rotated 90 degrees to the
right, boxes will fall, affected by gravity. Finds out a box which will have the longest ‘fall distance’, and
output the value of the longest ‘fall distance.
like there are 26 boxes in total (7 + 4 + 2 + 6 + 7 = 26). After rotating, gravity
affects all boxes and final state becomes like the room on the right. Among these 26 boxes, a ‘fall
distance’ of box A is the longest as 7, therefore, return 7.
For reference, a ‘fall distance’ of box B is 6, and a ‘fall distance’ of box C is 1. Gravity begins to apply after rotation is finished.
Boxes are stacked being adjacent to one side of the wall, thus all boxes are located in a two
dimensional plane. There is no box which is stacked apart from the wall. The width of the wall is always 100, and the height of the wall is always 100.
First line contains t, the number of test cases.
t test cases follow. Each test case has 2 lines. First line of each test case is n, the width of the
Next line contains n space separated integers representing the number of boxes in each stack.
The program should give output in separate line, for each test case
7 4 2 0 0 6 0 7 0