Challenge - 5 Problems
Delete Node Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput after deleting the first node in a singly linked list
What is the printed state of the linked list after deleting the first node?
DSA C#
public class Node { public int data; public Node next; public Node(int d) { data = d; next = null; } } public class LinkedList { public Node head; public void DeleteAtBeginning() { if (head != null) { head = head.next; } } public void PrintList() { Node temp = head; while (temp != null) { System.Console.Write(temp.data + " -> "); temp = temp.next; } System.Console.WriteLine("null"); } } class Program { static void Main() { LinkedList list = new LinkedList(); list.head = new Node(10); list.head.next = new Node(20); list.head.next.next = new Node(30); list.DeleteAtBeginning(); list.PrintList(); } }
Attempts:
2 left
💡 Hint
Deleting the first node means the head moves to the next node.
✗ Incorrect
Initially, the list is 10 -> 20 -> 30 -> null.
After deleting the first node (10), the head points to 20.
So the list becomes 20 -> 30 -> null.
❓ Predict Output
intermediateOutput when deleting from an empty linked list
What is the output when DeleteAtBeginning is called on an empty linked list and then printed?
DSA C#
public class Node { public int data; public Node next; public Node(int d) { data = d; next = null; } } public class LinkedList { public Node head; public void DeleteAtBeginning() { if (head != null) { head = head.next; } } public void PrintList() { Node temp = head; while (temp != null) { System.Console.Write(temp.data + " -> "); temp = temp.next; } System.Console.WriteLine("null"); } } class Program { static void Main() { LinkedList list = new LinkedList(); list.DeleteAtBeginning(); list.PrintList(); } }
Attempts:
2 left
💡 Hint
Deleting from an empty list should not change anything.
✗ Incorrect
The list is empty (head is null).
Deleting at beginning checks if head is not null, so nothing happens.
Printing the list shows just "null".
🔧 Debug
advancedIdentify the error in DeleteAtBeginning method
What error will occur when running this DeleteAtBeginning method on a non-empty list?
DSA C#
public void DeleteAtBeginning() {
head = head.next.next;
}Attempts:
2 left
💡 Hint
Check what happens if head.next is null.
✗ Incorrect
If the list has only one node, head.next is null.
Accessing head.next.next causes NullReferenceException.
🧠 Conceptual
advancedTime complexity of deleting the first node in a singly linked list
What is the time complexity of deleting the first node in a singly linked list?
Attempts:
2 left
💡 Hint
Deleting the first node only changes the head pointer.
✗ Incorrect
Deleting the first node just moves the head pointer to the next node.
This operation takes constant time, O(1).
❓ Predict Output
expertOutput after multiple deletions at beginning
What is the printed state of the linked list after deleting the first node twice?
DSA C#
public class Node { public int data; public Node next; public Node(int d) { data = d; next = null; } } public class LinkedList { public Node head; public void DeleteAtBeginning() { if (head != null) { head = head.next; } } public void PrintList() { Node temp = head; while (temp != null) { System.Console.Write(temp.data + " -> "); temp = temp.next; } System.Console.WriteLine("null"); } } class Program { static void Main() { LinkedList list = new LinkedList(); list.head = new Node(5); list.head.next = new Node(15); list.head.next.next = new Node(25); list.head.next.next.next = new Node(35); list.DeleteAtBeginning(); list.DeleteAtBeginning(); list.PrintList(); } }
Attempts:
2 left
💡 Hint
Each deletion moves the head to the next node.
✗ Incorrect
Initial list: 5 -> 15 -> 25 -> 35 -> null
After first deletion: 15 -> 25 -> 35 -> null
After second deletion: 25 -> 35 -> null
