Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if the doubly linked list is empty before deletion.
DSA Java
if (head == [1]) { return; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'head' instead of 'null' to check emptiness.
Checking 'tail' instead of 'head'.
✗ Incorrect
We check if head is null to know if the list is empty before deleting.
2fill in blank
mediumComplete the code to update the tail pointer when deleting the last node.
DSA Java
tail = tail.[1];Attempts:
3 left
💡 Hint
Common Mistakes
Using 'next' instead of 'prev' causing wrong pointer update.
Assigning tail to itself.
✗ Incorrect
To delete from end, tail moves to the previous node.
3fill in blank
hardFix the error in setting the new tail's next pointer to null after deletion.
DSA Java
if (tail != null) { tail.[1] = null; }
Attempts:
3 left
💡 Hint
Common Mistakes
Setting 'prev' to null instead of 'next'.
Setting 'head' or 'tail' to null incorrectly.
✗ Incorrect
The new tail's next pointer must be null to mark the list end.
4fill in blank
hardFill both blanks to handle the case when the list has only one node during deletion.
DSA Java
if (head == tail) { head = [1]; tail = [2]; }
Attempts:
3 left
💡 Hint
Common Mistakes
Setting head or tail to themselves instead of null.
Not updating both pointers.
✗ Incorrect
When only one node exists, deleting it sets both head and tail to null.
5fill in blank
hardFill all three blanks to complete the delete from end method in the doubly linked list.
DSA Java
public void deleteFromEnd() {
if (head == [1]) {
return;
}
if (head == tail) {
head = [2];
tail = [3];
return;
}
tail = tail.prev;
tail.next = null;
}Attempts:
3 left
💡 Hint
Common Mistakes
Using head or tail instead of null in checks and assignments.
Not returning after setting head and tail to null.
✗ Incorrect
Check if list is empty (head == null), then if only one node (head == tail), set both to null, else update tail and tail.next.
