Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the stack pointer.
DSA C
int stack[1000]; int top = [1];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Initializing top to 0 causes off-by-one errors.
Using a large number like 1000 causes invalid stack state.
✗ Incorrect
The stack pointer 'top' should start at -1 to indicate the stack is empty.
2fill in blank
mediumComplete the code to push an index onto the stack.
DSA C
stack[++top] = [1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Pushing height[i] instead of index causes wrong calculations.
Pushing top or stack[top] is incorrect.
✗ Incorrect
We push the current index 'i' onto the stack, not the height value.
3fill in blank
hardFix the error in the condition to pop from stack when current height is less.
DSA C
while (top != -1 && height[stack[top]] [1] height[i]) { // pop and calculate area }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' causes no popping and wrong area calculation.
Using '==' or '>=' changes logic incorrectly.
✗ Incorrect
We pop when the height at stack top is greater than current height to find smaller bars.
4fill in blank
hardFill both blanks to calculate width correctly after popping from stack.
DSA C
int width = top == -1 ? [1] : [2] - stack[top] - 1;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'top' or 'stack[top]' instead of 'i' causes wrong width.
Not subtracting 1 leads to off-by-one errors.
✗ Incorrect
If stack is empty, width is current index i; else width is difference between i and new top index minus one.
5fill in blank
hardFill all three blanks to finalize max area calculation inside the loop.
DSA C
int height_popped = height[stack[top--]]; int width = top == -1 ? [1] : [2] - stack[top] - 1; max_area = max(max_area, height_popped * [3]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'top' instead of 'width' in area calculation.
Mixing up variables for width calculation.
✗ Incorrect
Width is calculated same as before; max area updates with popped height times width.
