Challenge - 5 Problems
Doubly Linked List Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of Doubly Linked List after Insertions
What is the printed state of the doubly linked list after inserting nodes with values 10, 20, and 30 at the end?
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 append(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 new_node.prev = last def print_list(self): current = self.head result = [] while current: result.append(str(current.data)) current = current.next print(" -> ".join(result) + " -> null") dll = DoublyLinkedList() dll.append(10) dll.append(20) dll.append(30) dll.print_list()
Attempts:
2 left
💡 Hint
Think about how nodes are added at the end and how the print_list method traverses.
✗ Incorrect
Nodes are appended at the end, so the list order is 10, then 20, then 30. The print_list method prints from head to tail.
❓ Predict Output
intermediate2:00remaining
Value of Node after Deletion
What is the value of the head node after deleting the first node from the doubly linked list containing 5 -> 15 -> 25 -> null?
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 append(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 new_node.prev = last def delete_first(self): if not self.head: return if not self.head.next: self.head = None return self.head = self.head.next self.head.prev = None def print_list(self): current = self.head result = [] while current: result.append(str(current.data)) current = current.next print(" -> ".join(result) + " -> null") # Setup list_obj = DoublyLinkedList() list_obj.append(5) list_obj.append(15) list_obj.append(25) list_obj.delete_first() print(list_obj.head.data if list_obj.head else 'null')
Attempts:
2 left
💡 Hint
Deleting the first node moves the head to the next node.
✗ Incorrect
After deleting the first node (5), the head points to the next node which has value 15.
🔧 Debug
advanced2:00remaining
Identify the Bug in Node Link Update
What error occurs when running this code that inserts a new node after the head in 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 append(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 new_node.prev = last def insert_after_head(self, data): if not self.head: return new_node = Node(data) new_node.next = self.head.next if self.head.next: self.head.next.prev = new_node self.head.next = new_node new_node.prev = self.head # Setup list_obj = DoublyLinkedList() list_obj.append(1) list_obj.insert_after_head(2) list_obj.insert_after_head(3)
Attempts:
2 left
💡 Hint
Check what happens when head.next is None and you try to access head.next.prev.
✗ Incorrect
When head.next is None (list has only one node), accessing head.next.prev causes AttributeError because None has no attribute prev.
🧠 Conceptual
advanced1:30remaining
Understanding Node Connections in Doubly Linked List
In a doubly linked list, if a node's prev pointer is not updated correctly during insertion, what is the most likely consequence?
Attempts:
2 left
💡 Hint
Think about how prev pointers help in moving backwards through the list.
✗ Incorrect
If prev pointers are wrong, moving backwards through the list can fail or cause errors, corrupting the list structure.
🚀 Application
expert3:00remaining
Resulting List After Complex Operations
Given the following operations on an empty doubly linked list, what is the final printed list?
Operations:
1. Append 100
2. Append 200
3. Insert 150 after head
4. Delete first node
5. Append 250
6. Insert 175 after node with value 150
Print the list from head to tail.
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 append(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 new_node.prev = last def insert_after(self, prev_node_data, data): current = self.head while current and current.data != prev_node_data: current = current.next if not current: return new_node = Node(data) new_node.next = current.next if current.next: current.next.prev = new_node current.next = new_node new_node.prev = current def delete_first(self): if not self.head: return if not self.head.next: self.head = None return self.head = self.head.next self.head.prev = None def print_list(self): current = self.head result = [] while current: result.append(str(current.data)) current = current.next print(" -> ".join(result) + " -> null") # Operations list_obj = DoublyLinkedList() list_obj.append(100) list_obj.append(200) list_obj.insert_after(100, 150) list_obj.delete_first() list_obj.append(250) list_obj.insert_after(150, 175) list_obj.print_list()
Attempts:
2 left
💡 Hint
Follow each operation step-by-step and update the list accordingly.
✗ Incorrect
After deleting the first node (100), head becomes 150. Then 175 is inserted after 150, and 250 appended at the end. Final order is 150, 175, 200, 250.