Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare the function that calculates the maximum water container area.
DSA C
int maxArea(int* height, int heightSize) {
int [1] = 0;
return 0;
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name that is not descriptive or unrelated to the problem.
✗ Incorrect
The variable to store the maximum area is commonly named max_area to clearly indicate its purpose.
2fill in blank
mediumComplete the code to initialize the left pointer at the start of the array.
DSA C
int left = [1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Starting the left pointer at 1 or a negative index.
✗ Incorrect
The left pointer should start at index 0, which is the beginning of the array.
3fill in blank
hardFix the error in the while loop condition to correctly iterate while left is less than right.
DSA C
while (left [1] right) { // loop body }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using >= or > which causes the loop to skip or run incorrectly.
✗ Incorrect
The loop should continue while left is less than right to avoid overlapping pointers.
4fill in blank
hardFill both blanks to calculate the current area and update max_area if needed.
DSA C
int width = right - left; int height_min = height[left] < height[right] ? height[left] : height[right]; int current_area = width * [1]; if (current_area [2] max_area) { max_area = current_area; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong height for area calculation or wrong comparison operator.
✗ Incorrect
The current area is width times the smaller height (height_min). Update max_area if current_area is greater.
5fill in blank
hardFill all three blanks to move the pointers correctly based on the heights.
DSA C
if (height[left] < height[right]) { [1]++; } else { [2]--; } // Return the maximum area found return [3];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Moving the wrong pointer or returning the wrong variable.
✗ Incorrect
Move left pointer forward if height[left] is smaller, else move right pointer backward. Return max_area at the end.
