Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to push an element onto the stack.
DSA Java
stack.[1](value);Attempts:
3 left
💡 Hint
Common Mistakes
Using pop() instead of push() removes an element instead of adding.
Using peek() only views the top element without adding.
✗ Incorrect
The push() method adds an element to the top of the stack.
2fill in blank
mediumComplete the code to check if the stack is empty before pushing.
DSA Java
if (stack.[1]()) { stack.push(value); }
Attempts:
3 left
💡 Hint
Common Mistakes
Using isFull() checks if stack is full, not empty.
Using size() returns the number of elements but does not return boolean.
✗ Incorrect
The isEmpty() method checks if the stack has no elements.
3fill in blank
hardFix the error in the push method call to add element 10.
DSA Java
stack.[1](10);
Attempts:
3 left
💡 Hint
Common Mistakes
Using pop() removes the top element instead of adding.
Using peek() only views the top element.
✗ Incorrect
push(10) correctly adds the element 10 to the stack.
4fill in blank
hardFill both blanks to push value 5 onto the stack only if it is not full.
DSA Java
if (!stack.[1]()) { stack.[2](5); }
Attempts:
3 left
💡 Hint
Common Mistakes
Using isEmpty() instead of isFull() to check capacity.
Using pop() instead of push() to add element.
✗ Incorrect
Check if stack is not full with isFull(), then push the value.
5fill in blank
hardFill all three blanks to push the uppercase version of a string onto the stack if it is not empty.
DSA Java
if (!stack.[1]()) { stack.[2](word.[3]()); }
Attempts:
3 left
💡 Hint
Common Mistakes
Using pop() instead of push() to add element.
Using toLowerCase() instead of toUpperCase() for conversion.
✗ Incorrect
Check stack is not empty with isEmpty(), then push the uppercase word using toUpperCase().
