11. Container With Most Water
Intuition
To maximize the amount of water a container can hold, we need to consider the widest possible distance between two lines and the shortest height among them, as the water is limited by the shorter line.
If we start with the widest container (the first and last lines), we can try moving the pointer pointing to the shorter line inward. This is because the only way to potentially find a taller line (which could increase the area) is to discard the shorter one. Repeating this process will help us find the container with the maximum area.
Complexity
Space Complexity
Time Complexity
Code
Last updated