Complete the code to initialize the maximum area variable.
let maxArea = [1];We start with maxArea as 0 because initially we have no container area calculated.
Complete the code to calculate the current area between two lines.
const currentArea = Math.min(height[left], height[right]) * [1];
The width between two lines is the difference of their indices: right - left.
Fix the error in the pointer movement logic to find the maximum area.
if (height[left] < height[right]) { [1]; } else { right--; }
We move the left pointer forward when its height is less, to try to find a taller line.
Fill both blanks to update maxArea and move pointers correctly.
maxArea = Math.max(maxArea, [1]); if (height[left] < height[right]) { [2]; } else { right--; }
Update maxArea with the currentArea and move left pointer forward if left height is smaller.
Fill all three blanks to complete the container with most water function.
function maxAreaContainer(height: number[]): number {
let left = 0, right = height.length - 1;
let maxArea = 0;
while (left < right) {
const currentArea = Math.min(height[left], height[right]) * [1];
maxArea = Math.max(maxArea, currentArea);
if (height[left] < height[right]) {
[2];
} else {
[3];
}
}
return maxArea;
}The width is right - left. Move left pointer forward if left height is smaller, else move right pointer backward.
