Classic example
Input
heights = [1, 8, 6, 2, 5, 4, 8, 3, 7]
Output
49
Choose lines at indices 1 (height 8) and 8 (height 7): area = min(8,7) * (8-1) = 7 * 7 = 49.
Full lesson preview
Given heights of vertical lines on the x-axis, find the maximum area formed between any two lines using the two-pointer technique.
Problem statement
Task
Examples
Input
heights = [1, 8, 6, 2, 5, 4, 8, 3, 7]
Output
49
Choose lines at indices 1 (height 8) and 8 (height 7): area = min(8,7) * (8-1) = 7 * 7 = 49.
Input format
Output format
Constraints
Samples
Input
[1, 1]
Output
1
Only two lines with height 1 and distance 1 => area = 1.