left
at the start and right
at the end of the array.maxarea
to 0 to keep track of the maximum area found.left
is less than right
:
a. Calculate the current area as the product of the distance between the pointers and the height of the shorter line.
b. Update maxarea
if the current area is greater than the previously recorded maximum area.
c. Move the pointer pointing to the shorter line towards the other end by one step.
d. Repeat the process until left
meets right
.maxarea
as the result.