Medium · Two pointers
Container With Most Water
You are given a list, height. Each number is the height of a vertical line standing at that position. Choose two lines: with the ground between them they make a container. Return the most water any such container can hold.
- The water rises only as high as the shorter of the two lines.
- Amount = that shorter height × the distance between the two positions.
- The lines in between do not get in the way.
height = [1, 8, 6, 2, 5, 4, 8, 3, 7] → 49 (the 8 and the 7, seven apart: 7 × 7)Record your take