Challenge - 5 Problems
Head Insert Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput after inserting nodes at the beginning
What is the printed state of the linked list after inserting the values 10, 20, and 30 at the beginning in that order?
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 InsertAtBeginning(int newData) { Node newNode = new Node(newData); newNode.next = head; head = newNode; } public void PrintList() { Node temp = head; while (temp != null) { System.Console.Write(temp.data + " -> "); temp = temp.next; } System.Console.WriteLine("null"); } } LinkedList list = new LinkedList(); list.InsertAtBeginning(10); list.InsertAtBeginning(20); list.InsertAtBeginning(30); list.PrintList();
Attempts:
2 left
💡 Hint
Remember that inserting at the beginning means the newest node becomes the head.
✗ Incorrect
Each new node is added before the current head, so the list builds backwards: 30 is first, then 20, then 10.
❓ Predict Output
intermediateResulting list after multiple head inserts
What will be the output after inserting 5, then 15, then 25 at the beginning of an empty linked list and printing it?
DSA C#
LinkedList list = new LinkedList(); list.InsertAtBeginning(5); list.InsertAtBeginning(15); list.InsertAtBeginning(25); list.PrintList();
Attempts:
2 left
💡 Hint
The last inserted node is always the new head.
✗ Incorrect
Inserting at the beginning reverses the order of insertion in the list.
🔧 Debug
advancedIdentify the bug in head insertion
What error will occur when running this code that tries to insert a node at the beginning of a linked list?
DSA C#
public void InsertAtBeginning(int newData) {
Node newNode = new Node(newData);
newNode.next = head.next;
head = newNode;
}Attempts:
2 left
💡 Hint
Check what happens if head is null before accessing head.next.
✗ Incorrect
If head is null, accessing head.next causes a NullReferenceException.
🧠 Conceptual
advancedEffect of head insertion on list order
If you insert elements 1, 2, 3 in that order at the beginning of an empty linked list, what will be the order of elements when traversed from head?
Attempts:
2 left
💡 Hint
Each new node becomes the new head.
✗ Incorrect
Inserting at the beginning reverses the order of insertion.
🚀 Application
expertFinal list after mixed insertions
Given an empty linked list, you perform these operations in order:
1. Insert 100 at beginning
2. Insert 200 at beginning
3. Insert 300 at beginning
4. Insert 400 at beginning
What is the final printed list?
DSA C#
LinkedList list = new LinkedList(); list.InsertAtBeginning(100); list.InsertAtBeginning(200); list.InsertAtBeginning(300); list.InsertAtBeginning(400); list.PrintList();
Attempts:
2 left
💡 Hint
Remember the newest inserted node is always the head.
✗ Incorrect
Each insertion at the beginning places the new node before the current head, reversing insertion order.
