Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to update the head pointer when deleting the first node.
DSA Typescript
this.head = this.head[1];Attempts:
3 left
💡 Hint
Common Mistakes
Using .prev instead of .next to update head.
Trying to assign head to .data which is the node's value, not a node.
✗ Incorrect
When deleting the first node, the head should move to the next node in the list.
2fill in blank
mediumComplete the code to remove the backward link from the new head node.
DSA Typescript
if (this.head) this.head[1] = null;
Attempts:
3 left
💡 Hint
Common Mistakes
Setting .next to null instead of .prev.
Trying to set .head or .tail which are not node properties.
✗ Incorrect
After moving head forward, the new head's previous pointer should be null to disconnect from the old node.
3fill in blank
hardFix the error in the code that handles the case when the list becomes empty after deletion.
DSA Typescript
if (!this.head) this.[1] = null;
Attempts:
3 left
💡 Hint
Common Mistakes
Setting head to null again instead of tail.
Trying to set prev or next which are node properties, not list pointers.
✗ Incorrect
If the list is empty after deletion, the tail pointer should also be set to null.
4fill in blank
hardFill both blanks to correctly update the list size and return the deleted node's data.
DSA Typescript
this.size[1]; return deletedNode[2];
Attempts:
3 left
💡 Hint
Common Mistakes
Increasing size instead of decreasing.
Returning the whole node instead of its data.
✗ Incorrect
The size should decrease by one, and the data of the deleted node should be returned.
5fill in blank
hardFill all three blanks to complete the deleteFromBeginning method correctly.
DSA Typescript
if (!this.head) return null; const deletedNode = this.head; this.head = this.head[1]; if (this.head) this.head[2] = null; else this.[3] = null;
Attempts:
3 left
💡 Hint
Common Mistakes
Using .prev instead of .next for head update.
Setting head to null instead of tail when list is empty.
Not clearing the prev pointer of the new head.
✗ Incorrect
The head moves to the next node, the new head's prev is null, and if list is empty, tail is null.
