Challenge - 5 Problems
Linked List Deletion Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output after deleting the first node in a singly linked list
What will be the printed linked list after deleting the first node?
DSA C
#include <stdio.h> #include <stdlib.h> struct Node { int data; struct Node* next; }; void printList(struct Node* head) { while (head != NULL) { printf("%d -> ", head->data); head = head->next; } printf("NULL\n"); } struct Node* deleteAtBeginning(struct Node* head) { if (head == NULL) return NULL; struct Node* temp = head; head = head->next; free(temp); return head; } int main() { struct Node* head = malloc(sizeof(struct Node)); struct Node* second = malloc(sizeof(struct Node)); struct Node* third = malloc(sizeof(struct Node)); head->data = 10; head->next = second; second->data = 20; second->next = third; third->data = 30; third->next = NULL; head = deleteAtBeginning(head); printList(head); return 0; }
Attempts:
2 left
💡 Hint
Deleting the first node means the head moves to the next node.
✗ Incorrect
The function deleteAtBeginning removes the first node (which has data 10) and returns the new head pointing to the second node. So the list starts from 20 now.
🧠 Conceptual
intermediate1:00remaining
Effect of deleting the first node on list length
If a singly linked list has 5 nodes, how many nodes remain after deleting the first node?
Attempts:
2 left
💡 Hint
Deleting one node reduces the count by one.
✗ Incorrect
Deleting the first node removes exactly one node from the list, so 5 - 1 = 4 nodes remain.
🔧 Debug
advanced2:00remaining
Identify the error in deleting the first node
What error will occur when running this code snippet to delete the first node?
DSA C
#include <stdio.h> #include <stdlib.h> struct Node { int data; struct Node* next; }; struct Node* deleteAtBeginning(struct Node* head) { struct Node* temp = head; head = head->next; free(temp); return head; } int main() { struct Node* head = NULL; head = deleteAtBeginning(head); return 0; }
Attempts:
2 left
💡 Hint
Check what happens if head is NULL before accessing head->next.
✗ Incorrect
The function does not check if head is NULL before accessing head->next. This causes a segmentation fault when head is NULL.
📝 Syntax
advanced2:00remaining
Correct syntax to delete the first node in a linked list
Which option correctly deletes the first node and updates the head pointer?
DSA C
struct Node* deleteAtBeginning(struct Node* head) {
// Choose the correct implementation
}Attempts:
2 left
💡 Hint
Always check if the list is empty before deleting.
✗ Incorrect
Option B correctly checks if head is NULL before deleting. It saves the current head in temp, moves head to the next node, frees the old head, and returns the new head.
🚀 Application
expert3:00remaining
Resulting list after multiple deletions at beginning
Given a linked list with nodes 5 -> 10 -> 15 -> 20 -> NULL, what is the list after deleting the first node twice?
Attempts:
2 left
💡 Hint
Each deletion removes the current head node.
✗ Incorrect
First deletion removes 5, list becomes 10 -> 15 -> 20 -> NULL.
Second deletion removes 10, list becomes 15 -> 20 -> NULL.
