Challenge - 5 Problems
Singly Linked List Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of Inserting Nodes in a Singly Linked List
What is the printed state of the linked list after inserting nodes with values 10, 20, and 30 in that order?
DSA Python
class Node: def __init__(self, data): self.data = data self.next = None class SinglyLinkedList: def __init__(self): self.head = None def insert_at_end(self, data): new_node = Node(data) if not self.head: self.head = new_node return current = self.head while current.next: current = current.next current.next = new_node def print_list(self): current = self.head while current: print(current.data, end=' -> ' if current.next else ' -> null\n') current = current.next sll = SinglyLinkedList() sll.insert_at_end(10) sll.insert_at_end(20) sll.insert_at_end(30) sll.print_list()
Attempts:
2 left
💡 Hint
Think about how nodes are added at the end and how the list is printed from head to tail.
✗ Incorrect
Nodes are inserted at the end, so the order is the same as insertion: 10, then 20, then 30. The print_list method prints from head to tail, showing 10 -> 20 -> 30 -> null.
🧠 Conceptual
intermediate1:00remaining
Understanding the Head Pointer in a Singly Linked List
What does the 'head' pointer in a singly linked list represent?
Attempts:
2 left
💡 Hint
Think about where the list starts when you want to traverse it.
✗ Incorrect
The head pointer always points to the first node of the list, which is the starting point for traversing the list.
🔧 Debug
advanced2:00remaining
Identify the Error in Node Insertion Code
What error will occur when running this code to insert a node at the end of the list?
DSA Python
class Node: def __init__(self, data): self.data = data self.next = None class SinglyLinkedList: def __init__(self): self.head = None def insert_at_end(self, data): new_node = Node(data) if self.head is None: self.head = new_node else: current = self.head while current.next: current = current.next current.next = new_node sll = SinglyLinkedList() sll.insert_at_end(5) sll.insert_at_end(15) sll.insert_at_end(25) print(sll.head.next.next.next.data)
Attempts:
2 left
💡 Hint
Check how many nodes are in the list and what happens when accessing next pointers.
✗ Incorrect
The list has three nodes, so sll.head.next.next.next is None. Trying to access .data on None causes AttributeError.
❓ Predict Output
advanced2:00remaining
Output After Deleting a Node from Singly Linked List
What is the printed state of the linked list after deleting the node with value 20?
DSA Python
class Node: def __init__(self, data): self.data = data self.next = None class SinglyLinkedList: def __init__(self): self.head = None def insert_at_end(self, data): new_node = Node(data) if not self.head: self.head = new_node return current = self.head while current.next: current = current.next current.next = new_node def delete_node(self, key): current = self.head prev = None while current and current.data != key: prev = current current = current.next if not current: return if prev is None: self.head = current.next else: prev.next = current.next def print_list(self): current = self.head while current: print(current.data, end=' -> ' if current.next else ' -> null\n') current = current.next sll = SinglyLinkedList() sll.insert_at_end(10) sll.insert_at_end(20) sll.insert_at_end(30) sll.delete_node(20) sll.print_list()
Attempts:
2 left
💡 Hint
Deleting a node removes it from the chain, so it won't appear in the printed list.
✗ Incorrect
The node with value 20 is removed, so the list contains 10 followed by 30.
🧠 Conceptual
expert1:30remaining
Time Complexity of Searching in a Singly Linked List
What is the time complexity of searching for a value in a singly linked list with n nodes?
Attempts:
2 left
💡 Hint
You may need to check each node one by one in the worst case.
✗ Incorrect
Searching requires checking nodes one by one until the value is found or list ends, so it takes linear time O(n).