Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to update the head pointer when deleting the first node.
DSA Javascript
this.head = this.head[1];Attempts:
3 left
💡 Hint
Common Mistakes
Using .prev instead of .next causes the head to point backward.
Using .data instead of a node reference breaks the list structure.
✗ Incorrect
When deleting the first node, the head should point to the next node in the list.
2fill in blank
mediumComplete the code to set the previous pointer of the new head to null after deletion.
DSA Javascript
if (this.head) this.head[1] = null;
Attempts:
3 left
💡 Hint
Common Mistakes
Setting .next to null disconnects the list incorrectly.
Forgetting to check if head exists before setting .prev causes errors.
✗ Incorrect
After deleting the first node, the new head's previous pointer should be null.
3fill in blank
hardFix the error in the code that handles the case when the list becomes empty after deletion.
DSA Javascript
if (!this.head) this.[1] = null;
Attempts:
3 left
💡 Hint
Common Mistakes
Setting head to null again is redundant here.
Setting next or prev to null does not update the list pointers correctly.
✗ Incorrect
When the list is empty, both head and tail should be null. Here, tail is set to null.
4fill in blank
hardFill both blanks to complete the deleteFromBeginning method that removes the first node.
DSA Javascript
deleteFromBeginning() {
if (!this.head) return null;
const removed = this.head;
this.head = this.head[1];
if (this.head) this.head[2] = null;
else this.tail = null;
return removed.data;
}Attempts:
3 left
💡 Hint
Common Mistakes
Swapping .next and .prev causes incorrect pointer updates.
Not setting tail to null when list becomes empty.
✗ Incorrect
The head moves to the next node, and the new head's previous pointer is set to null.
5fill in blank
hardFill all three blanks to complete the full deleteFromBeginning method with proper pointer updates and return value.
DSA Javascript
deleteFromBeginning() {
if (!this.head) return null;
const removed = this.head;
this.head = this.head[1];
if (this.head) this.head[2] = null;
else this.[3] = null;
return removed.data;
}Attempts:
3 left
💡 Hint
Common Mistakes
Setting head to null instead of tail in the else block.
Forgetting to return removed.data.
✗ Incorrect
The head moves to next, new head's prev is null, and tail is set to null if list is empty.
