Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to push elements 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 the index instead of the element.
Using top instead of arr[i].
✗ Incorrect
We push the current array element arr[i] onto the stack to find its next greater element later.
2fill in blank
mediumComplete the condition to check if the stack is not empty.
DSA C
while (top [1] -1 && stack[top] <= arr[i]) {
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '>' to check stack emptiness.
Using '<' which is incorrect here.
✗ Incorrect
The stack is not empty if top > -1.
3fill in blank
hardFix the error in assigning the next greater element.
DSA C
result[i] = [1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning arr[i] instead of stack[top].
Assigning -1 incorrectly here.
✗ Incorrect
The next greater element for arr[i] is the top element of the stack.
4fill in blank
hardFill both blanks to correctly initialize the stack and result arrays.
DSA C
int stack[[1]], result[[2]];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'top' or 'i' as array sizes.
Using 'arr' which is not a size.
✗ Incorrect
Both stack and result arrays should be of size n, the number of elements.
5fill in blank
hardFill all three blanks to complete the loop that assigns -1 to elements with no next greater element.
DSA C
for ([1] = 0; [2] < [3]; [2]++) { result[i] = -1; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variables for loop initialization and condition.
Using 'top' instead of 'n' for loop limit.
✗ Incorrect
Use 'i' as the loop variable and 'n' as the limit to assign -1 to all elements without a next greater element.
