Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Manga Guide To Databases

Authors: Mana Takahashi, Shoko Azuma, Co Ltd Trend

1st Edition

1593271905, 978-1593271909

More Books

Students also viewed these Databases questions

Question

6. What actions might make employers lose elections?

Answered: 1 week ago