Question: Problem 5. (20 points) Given n non-negative integers ai,a2, ....an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such

Problem 5. (20 points) Given n non-negative integers ai,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. 1. Solve the problem with brute-force approach. What is the time complexity of this approach? 2. Is there any better solution? If so, describe your solution with time complexity analysis. Note: You may not slant the container and n is at least 2
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
