Container with Most Water Problem Statement
Given a sequence of 'N' space-separated non-negative integers A[1], A[2], ..., A[i], ..., A[n], where each number in the sequence represents the height of a line drawn at point 'i'. On the Cartesian plane, each line is drawn from coordinate ('i', 0) to coordinate ('i', 'A[i]'). The task is to find two lines such that, together with the x-axis, they form a container that can hold the maximum area of water.
Input:
The first line of input contains an integer 'T' representing 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.
Output:
For each test case, return the area of the container that can hold the maximum amount of water using any pair of lines from the given sequence.
Example:
Explanation:
In the provided diagram example, suppose 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 is calculated as (height * width) = (5-2) * 9 = 27, which is the maximum area that can be contained between any two lines on the plane. Therefore, the function should return 3* 9 = 27 in this scenario.
Constraints:
- 1 <= T <= 50
- 0 <= N <= 10^4
- 1 <= A[i] <= 10^5
- Time Limit: 1 second
Note:
1. You cannot slant the container; the height of the water is equal to the minimum height of the two lines that form the container.
2. Do not print anything; simply return the maximum water area the container can hold.
Given a sequence of non-negative integers representing the height of lines on a cartesian plane, find two lines that form a container with the maximum area of water.
Use two pointers approach to find t...read more
Top Amazon Software Developer Intern interview questions & answers
Popular interview questions of Software Developer Intern
Top HR questions asked in Amazon Software Developer Intern
Reviews
Interviews
Salaries
Users/Month