1. You can not slant the container i.e. the height of the water is equal to the minimum height of the two lines which define the container.
2. Do not print anything, you just need to return the area of the container with maximum water.
For the above Diagram, the first red marked line is formed between coordinates (2,0) and (2,10), and the second red-marked line is formed between coordinates (5,0) and (5,9). The area of water contained between these two lines is (height* width) = (5-2)* 9 = 27, which is the maximum area contained between any two lines present on the plane. So in this case, we will return 3* 9=27.
The first line of input contains an integer ‘T’ denoting the number of test cases.
The next ‘2*T’ lines represent the ‘T’ test cases.
The first line of each test case contains the number of elements in the sequence.
The second line of each test case contains ‘n’ space-separated integers which is the given sequence.
For every test case return the area of the container which can hold the maximum amount of water using any pair of lines from the given sequence.
1 <= T <= 50
0 <= N <= 10^4
1 <= A[i] <= 10^5
Time Limit: 1 sec
Since we need to find the container with most water, let us try to find all possible containers and choose the one which has the maximum area.
So how can we find the area of all possible containers?
We can, for each line with the position ‘i’ find another line ‘j’ such that ‘j’ > ‘i’ and find the amount of water contained i.e (‘j’-’i’)*min('A[i]', ‘A[j]’) where ‘A[i]’ and ‘A[j]’ represents the height of the lines at index ‘i’ and ‘j’ respectively.
We can do this in the following way:
Missing Number
Longest Subarray With Zero Sum
Merge Two Sorted Arrays Without Extra Space
Ninja And The Strictly Increasing Array
Negative To The End