Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to move to the last node in the doubly linked list.
DSA Javascript
while (current.next [1] null) { current = current.next; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using == instead of !== causes the loop to stop immediately.
Using = assigns instead of compares, causing errors.
✗ Incorrect
We use !== null to continue moving until the next node is null, which means current is the last node.
2fill in blank
mediumComplete the code to update the previous node's next pointer when deleting the last node.
DSA Javascript
if (current.prev) { current.prev.[1] = null; }
Attempts:
3 left
💡 Hint
Common Mistakes
Setting prev instead of next breaks the list links.
Setting value or head does not affect the node connections.
✗ Incorrect
We set the previous node's next pointer to null to remove the last node from the list.
3fill in blank
hardFix the error in updating the head when the list has only one node.
DSA Javascript
if (!current.prev) { [1] = null; }
Attempts:
3 left
💡 Hint
Common Mistakes
Setting current or tail to null does not update the list head.
Setting prev to null does not remove the node from the list.
✗ Incorrect
If the current node has no previous node, it means it's the head, so we set head to null after deletion.
4fill in blank
hardFill both blanks to correctly delete the last node and update the tail pointer.
DSA Javascript
if (current.prev) { current.prev.[1] = null; [2] = current.prev; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using prev instead of next breaks the link.
Updating head instead of tail causes incorrect list end.
✗ Incorrect
We set the previous node's next to null and update tail to point to the previous node after deletion.
5fill in blank
hardFill all three blanks to complete the delete from end function for a doubly linked list.
DSA Javascript
function deleteFromEnd() {
if (!head) return null;
let current = head;
while (current.next [1] null) {
current = current.next;
}
if (current.prev) {
current.prev.[2] = null;
[3] = current.prev;
} else {
head = null;
tail = null;
}
}Attempts:
3 left
💡 Hint
Common Mistakes
Using == instead of !== causes incorrect loop behavior.
Setting prev instead of next breaks the list.
Not updating tail causes tail to point to deleted node.
✗ Incorrect
We loop while current.next !== null to reach the last node, set current.prev.next to null to remove it, and update tail to current.prev.
