Zee
Zee

Reputation: 13

Container with most water algorithm issue

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

What I do not understand about this question is how am I supposed to know the y-coordinate value(height) of the n vertical lines.

Upvotes: 0

Views: 447

Answers (1)

four_lines
four_lines

Reputation: 503

If the values you are given are {1,2,3,4,4,1,3}, the vertical lines would be:

4|          |  |
3|       |  |  |     |
2|    |  |  |  |     |
1| |  |  |  |  |  |  |
0| -------------------
   1  2  3  4  5  6  7

ai is the height of the ith line, and it's x coordinate is i.

Upvotes: 1

Related Questions