Skip to content
Discussion options

You must be logged in to vote

We need to find the maximum amount of water that can be contained between two vertical lines in an array, where the amount of water is determined by the distance between the lines and the height of the shorter line. The solution involves using the two-pointer technique to efficiently find the maximum area without checking all possible pairs, which would be inefficient.

Approach

  1. Two-Pointer Technique: We use two pointers, one starting at the beginning (left) and the other at the end (right) of the array.
  2. Calculate Area: For each pair of lines pointed to by the left and right pointers, calculate the area formed between them. The area is computed as the product of the distance between the l…

Replies: 1 comment 2 replies

Comment options

mah-shamim
Oct 4, 2025
Maintainer Author

You must be logged in to vote
2 replies
@topugit
Comment options

topugit Oct 4, 2025
Collaborator

@mah-shamim
Comment options

mah-shamim Oct 4, 2025
Maintainer Author

Answer selected by topugit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested medium Difficulty
2 participants