Challenge - 5 Problems
Node Structure Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of a singly linked list after insertions
What is the printed output 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 LinkedList: def __init__(self): self.head = None def insert_end(self, data): new_node = Node(data) if not self.head: self.head = new_node return last = self.head while last.next: last = last.next last.next = new_node def print_list(self): current = self.head while current: print(current.data, end=' -> ') current = current.next print('null') ll = LinkedList() ll.insert_end(10) ll.insert_end(20) ll.insert_end(30) ll.print_list()
Attempts:
2 left
💡 Hint
Think about how nodes are added at the end of the list.
✗ Incorrect
Nodes are inserted at the end, so the order is the same as insertion: 10, then 20, then 30.
❓ Predict Output
intermediate2:00remaining
Output after reversing a singly linked list
What is the output of the linked list after reversing it?
DSA Python
class Node: def __init__(self, data): self.data = data self.next = None class LinkedList: def __init__(self): self.head = None def insert_end(self, data): new_node = Node(data) if not self.head: self.head = new_node return last = self.head while last.next: last = last.next last.next = new_node def reverse(self): prev = None current = self.head while current: next_node = current.next current.next = prev prev = current current = next_node self.head = prev def print_list(self): current = self.head while current: print(current.data, end=' -> ') current = current.next print('null') ll = LinkedList() ll.insert_end(1) ll.insert_end(2) ll.insert_end(3) ll.reverse() ll.print_list()
Attempts:
2 left
💡 Hint
Reversing changes the direction of the pointers.
✗ Incorrect
Reversing the list makes the last node the new head, so the order is 3, 2, 1.
🔧 Debug
advanced2:00remaining
Identify the error in doubly linked list node insertion
What error will occur when running this code that inserts a node at the beginning of a doubly linked list?
DSA Python
class Node: def __init__(self, data): self.data = data self.prev = None self.next = None class DoublyLinkedList: def __init__(self): self.head = None def insert_beginning(self, data): new_node = Node(data) new_node.next = self.head if self.head: self.head.prev = new_node self.head = new_node dll = DoublyLinkedList() dll.insert_beginning(5) dll.insert_beginning(10) print(dll.head.prev.data)
Attempts:
2 left
💡 Hint
Check what happens to the prev pointer of the head node.
✗ Incorrect
After inserting 10 at beginning, head.prev is None, so accessing head.prev.data causes AttributeError.
🧠 Conceptual
advanced1:30remaining
Pointer design in circular linked list
In a circular singly linked list with one node, what does the node's next pointer point to?
Attempts:
2 left
💡 Hint
In circular lists, the last node connects back to the first node.
✗ Incorrect
With one node, its next pointer points to itself to maintain the circular structure.
❓ Predict Output
expert2:30remaining
Output after complex pointer manipulation in linked list
What is the output after executing the following code that manipulates pointers in a linked list?
DSA Python
class Node: def __init__(self, data): self.data = data self.next = None class LinkedList: def __init__(self): self.head = None def insert_end(self, data): new_node = Node(data) if not self.head: self.head = new_node return last = self.head while last.next: last = last.next last.next = new_node def manipulate(self): if not self.head or not self.head.next: return first = self.head second = first.next third = second.next # Swap first and second nodes by changing pointers second.next = first first.next = third self.head = second def print_list(self): current = self.head while current: print(current.data, end=' -> ') current = current.next print('null') ll = LinkedList() ll.insert_end(1) ll.insert_end(2) ll.insert_end(3) ll.manipulate() ll.print_list()
Attempts:
2 left
💡 Hint
The manipulate method swaps the first two nodes by changing pointers.
✗ Incorrect
The method swaps first and second nodes by redirecting pointers, so the list becomes 2 -> 1 -> 3 -> null.