Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if the list is empty before deletion.
DSA Java
if (head == [1]) { System.out.println("List is empty"); return; }
Attempts:
3 left
💡 Hint
Common Mistakes
Checking if head equals tail instead of null.
Using value variable instead of head.
✗ Incorrect
We check if head is null to know if the list is empty.
2fill in blank
mediumComplete the code to traverse the list to find the node with the given value.
DSA Java
Node current = head; while (current != [1] && current.data != value) { current = current.next; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using head instead of null in the loop condition.
Comparing current.data with head instead of value.
✗ Incorrect
We traverse until current is null or we find the value.
3fill in blank
hardFix the error in updating the previous node's next pointer when deleting a middle node.
DSA Java
if (current.prev != null) { current.prev.[1] = current.next; }
Attempts:
3 left
💡 Hint
Common Mistakes
Updating prev pointer instead of next.
Trying to update data or value fields.
✗ Incorrect
We update the previous node's next pointer to skip the current node.
4fill in blank
hardFill both blanks to update the next node's previous pointer and handle tail update.
DSA Java
if (current.next != null) { current.next.[1] = current.prev; } else { tail = [2]; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using next instead of prev for next node's pointer.
Setting tail to current.next instead of current.prev.
✗ Incorrect
We update the next node's prev pointer to current's prev and update tail if current is last.
5fill in blank
hardFill all three blanks to handle deleting the head node and freeing the current node.
DSA Java
if (current == head) { head = [1]; } current.[2] = null; current.[3] = null;
Attempts:
3 left
💡 Hint
Common Mistakes
Not updating head when deleting first node.
Clearing data instead of pointers.
Mixing prev and next pointers.
✗ Incorrect
When deleting head, update head to next node. Then clear current's prev and next to help garbage collection.
