You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, heighti).
Find two lines that together with the x-axis form a container, such that the container contains the most water.
Return the maximum amount of the water a container can store.
Examples:

1 | Input: height = [1, 8, 6, 2, 5, 4, 8, 3, 7]; |
1 | Input: height = [1, 1]; |
Constraints:
- n = len(height)
- 2 ≤ n ≤ 105
- 0 ≤ heighti ≤ 104
Solution
1 | class Solution { |
Explanation:
To solve this problem the two pointers technique is adopted. The left pointer starting at the index 0 and the right pointer starts at the end of the vector. Use maxA to keep track of the maximum area found. Then calculate the current area of the container and update it to the maxA. And we need to move the two pointers inwards to find the global maximum area. The method for moving inwards the pointers is to always move the smaller one (low one) the seeking a greater value that may increase the area.