Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare the stack array for storing indices.
DSA C
int stack[[1]]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 or negative size for the stack array.
Using too small size like 10 which may not hold all indices.
✗ Incorrect
The stack size should be large enough to hold all indices, so 1000 is a safe choice.
2fill in blank
mediumComplete the code to initialize the top of the stack.
DSA C
int top = [1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Initializing top to 0 which means stack is not empty.
Using a large number like 1000 which is out of bounds.
✗ Incorrect
The top is initialized to -1 to indicate the stack is empty.
3fill in blank
hardFix the error in the while loop condition to pop prices less than or equal to the current price from the stack.
DSA C
while (top >= 0 && prices[stack[top]] [1] prices[i]) { top--; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' which does not pop equal prices.
Using '>=' or '>' which reverses the logic.
✗ Incorrect
We pop while the price at stack top is less than or equal to the current price.
4fill in blank
hardFill both blanks to calculate the span correctly.
DSA C
span[i] = (top == -1) ? [1] : i - stack[2];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using i - 1 instead of i + 1 for empty stack case.
Using stack[top - 1] which may cause wrong index.
✗ Incorrect
If stack is empty, span is i+1; else span is difference between current index and top index in stack.
5fill in blank
hardFill all three blanks to push current index onto stack and print the spans.
DSA C
stack[++top] = [1]; for (int j = 0; j < n; j++) { printf("%d ", [2][[3]]); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Pushing wrong variable onto stack.
Printing prices instead of span.
Using wrong loop variable in print.
✗ Incorrect
Push current index i onto stack; print span[j] for all j from 0 to n-1.
