The algorithm: Initialize left = , right = - , maxArea = While left < right: - Calculate current area = min(height[left], height[right]) × (right - left) - Update maxArea if current is larger - Move the pointer pointing to the shorter line Return maxArea Why does this work? Moving the taller pointer can never increase the area (height is limited by the shorter line, and width decreases). Moving the shorter pointer might find a taller line.
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
$ curl repovive.com/roadmaps/maang-interview-prep/two-pointers-sliding-window/container-with-most-water-solution
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░████████████████████████████████████████████████████████████████████████████████████████████████████████████████