Complete the code to initialize the stack for indices.
const stack: number[] = [1];We use an empty array [] to initialize the stack for indices.
Complete the code to push the current index onto the stack.
stack.[1](i);We use push to add the current index i to the top of the stack.
Fix the error in the condition to pop from stack when current height is less than height at stack top.
while (stack.length > 0 && heights[i] [1] heights[stack[stack.length - 1]]) {
We pop from the stack when the current height is less than the height at the top of the stack.
Fill both blanks to calculate the width correctly after popping from stack.
const width = stack.length === 0 ? i : i [1] stack[stack.length [2] 1] - 1;
The width is calculated as i - stack top - 1 if stack is not empty, else i.
Fill all three blanks to compute area and update max area correctly.
const area = heights[top] * [1]; maxArea = Math.[2](maxArea, area); stack.[3]();
Area is height times width. We update maxArea using Math.max and remove the top of the stack with pop.
