Question: Given n non - negative integers a 1 , a 2 , . . . , an , where each represents a point at coordinate

Given n non-negative integers a1, a2,..., an, where each represents a point at coordinate (i, ai). n vertical
lines are drawn such that the two endpoints of line i is at (i, ai) and (i,0). Find two lines, which together
with x-axis forms a container, such that the container contains the most water. Here are some examples:
Example 1:
Input: array =[1,5,4,3]
Output: 6
Explanation : 5 and 3 are distance 2 apart. So the size of the base =2. Height of container =
min(5,3)=3. So total area =3*2=6
Example 2:
Input: array =[3,1,2,4,5]
Output: 12
Explanation : 5 and 3 are distance 4 apart. So the size of the base =4. Height of container =
min(5,3)=3. So total area =4*3=12
1. Solve the problem with brute-force approach by providing the pseudo-code for this problem. What is
the time complexity of this approach?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!