The O(n) requirement is what makes this non-trivial.
Start by clarifying the problem: the container's area is determined by the shorter line and the distance between lines. Use a two-pointer technique starting from the widest possible container and moving inward, always moving the pointer at the shorter line, to achieve O(n) time.
Pro tip: Explain why moving the shorter line is safe: any container formed with the shorter line and a closer line will have less width and no greater height, so it cannot be better. This demonstrates deep understanding and avoids brute-force.
Restate the problem: given an array of heights, find two lines that together with the x-axis form a container holding the most water. Confirm that the container cannot be slanted and that the area is min(height[i], height[j]) * (j - i).
Mention that checking all pairs takes O(n^2) time, which is inefficient for large inputs. This sets the stage for the optimal solution.
Initialize two pointers at the beginning and end of the array. Compute the area and update the maximum. Then move the pointer pointing to the shorter line inward, because the width decreases and the height is limited by the shorter line.
Argue that moving the shorter pointer is safe: any other container involving that shorter line and a closer line will have less width and no greater height, so it cannot yield a larger area. The algorithm runs in O(n) time and O(1) space.
Trace the algorithm on a small example, such as [1,8,6,2,5,4,8,3,7], to demonstrate how the maximum area is found and to verify the logic.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.