Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to delete the first node of the linked list.
DSA Javascript
function deleteAtBeginning(head) {
if (head === null) return null;
return [1];
}Attempts:
3 left
💡 Hint
Common Mistakes
Returning head instead of head.next
Returning null without checking
Trying to access head.prev in singly linked list
✗ Incorrect
To delete the first node, we return the second node which is head.next.
2fill in blank
mediumComplete the code to update the head pointer after deleting the first node.
DSA Javascript
function deleteAtBeginning(head) {
if (head === null) return null;
let newHead = [1];
return newHead;
}Attempts:
3 left
💡 Hint
Common Mistakes
Using head.prev which does not exist in singly linked list
Assigning newHead to head itself
Assigning newHead to null without checking
✗ Incorrect
The new head after deletion is the next node of the current head.
3fill in blank
hardFix the error in the code to correctly delete the first node and return the updated list.
DSA Javascript
function deleteAtBeginning(head) {
if (head === null) return null;
head = [1];
return head;
}Attempts:
3 left
💡 Hint
Common Mistakes
Assigning head to itself causing no deletion
Assigning head to null causing empty list
Using head.prev which is undefined
✗ Incorrect
Assigning head to head.next removes the first node from the list.
4fill in blank
hardFill both blanks to delete the first node and update the head correctly.
DSA Javascript
function deleteAtBeginning(head) {
if (head === null) return null;
let temp = [1];
head = [2];
return head;
}Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the order of assignments
Using head.prev which does not exist
Assigning temp to head.next instead of head
✗ Incorrect
We store the current head in temp, then update head to head.next to delete the first node.
5fill in blank
hardFill all three blanks to delete the first node and return the updated list safely.
DSA Javascript
function deleteAtBeginning(head) {
if (head === null) return null;
let temp = [1];
head = [2];
temp = [3];
return head;
}Attempts:
3 left
💡 Hint
Common Mistakes
Not clearing temp after deletion
Using head.prev which is undefined
Assigning temp to head.next instead of null
✗ Incorrect
We save the current head in temp, update head to head.next, then clear temp to null to help garbage collection.
