Challenge - 5 Problems
Circular Linked List Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of Circular Singly Linked List after Insertions
What is the printed output of the circular singly 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 CircularSinglyLinkedList: def __init__(self): self.head = None def insert(self, data): new_node = Node(data) if not self.head: self.head = new_node new_node.next = new_node else: temp = self.head while temp.next != self.head: temp = temp.next temp.next = new_node new_node.next = self.head def print_list(self): if not self.head: print("List is empty") return temp = self.head result = [] while True: result.append(str(temp.data)) temp = temp.next if temp == self.head: break print(" -> ".join(result) + " -> (head)") cll = CircularSinglyLinkedList() cll.insert(10) cll.insert(20) cll.insert(30) cll.print_list()
Attempts:
2 left
💡 Hint
Remember that in a circular singly linked list, the last node points back to the head.
✗ Incorrect
Nodes are inserted at the end, and the last node points back to the head, so the print shows 10 -> 20 -> 30 -> (head).
❓ Predict Output
intermediate2:00remaining
Result of Deleting Head Node in Circular Singly Linked List
What is the printed output after deleting the head node from the circular singly linked list containing 5 -> 15 -> 25 -> (head)?
DSA Python
class Node: def __init__(self, data): self.data = data self.next = None class CircularSinglyLinkedList: def __init__(self): self.head = None def insert(self, data): new_node = Node(data) if not self.head: self.head = new_node new_node.next = new_node else: temp = self.head while temp.next != self.head: temp = temp.next temp.next = new_node new_node.next = self.head def delete_head(self): if not self.head: return if self.head.next == self.head: self.head = None return temp = self.head while temp.next != self.head: temp = temp.next temp.next = self.head.next self.head = self.head.next def print_list(self): if not self.head: print("List is empty") return temp = self.head result = [] while True: result.append(str(temp.data)) temp = temp.next if temp == self.head: break print(" -> ".join(result) + " -> (head)") cll = CircularSinglyLinkedList() cll.insert(5) cll.insert(15) cll.insert(25) cll.delete_head() cll.print_list()
Attempts:
2 left
💡 Hint
Deleting the head means the second node becomes the new head.
✗ Incorrect
After deleting the head (5), the list starts from 15 and continues to 25, then back to 15.
🔧 Debug
advanced2:00remaining
Identify the Bug in Circular Singly Linked List Insertion
What is the bug in the following insert method of a circular singly linked list?
DSA Python
def insert(self, data): new_node = Node(data) if not self.head: self.head = new_node new_node.next = None else: temp = self.head while temp.next != self.head: temp = temp.next temp.next = new_node new_node.next = self.head
Attempts:
2 left
💡 Hint
Check what happens when the list is empty and a new node is inserted.
✗ Incorrect
When the list is empty, new_node.next should point to itself to maintain circularity, but it is set to None, breaking the circle.
❓ Predict Output
advanced2:00remaining
Output after Traversing Circular Singly Linked List with One Node
What is the output of the print_list method when the circular singly linked list has only one node with value 42?
DSA Python
class Node: def __init__(self, data): self.data = data self.next = None class CircularSinglyLinkedList: def __init__(self): self.head = None def insert(self, data): new_node = Node(data) if not self.head: self.head = new_node new_node.next = new_node else: temp = self.head while temp.next != self.head: temp = temp.next temp.next = new_node new_node.next = self.head def print_list(self): if not self.head: print("List is empty") return temp = self.head result = [] while True: result.append(str(temp.data)) temp = temp.next if temp == self.head: break print(" -> ".join(result) + " -> (head)") cll = CircularSinglyLinkedList() cll.insert(42) cll.print_list()
Attempts:
2 left
💡 Hint
A single node points to itself in a circular singly linked list.
✗ Incorrect
The single node points back to itself, so the print shows 42 -> (head).
🧠 Conceptual
expert2:00remaining
Why Use Circular Singly Linked List Instead of Singly Linked List?
Which of the following is the main advantage of using a circular singly linked list over a regular singly linked list?
Attempts:
2 left
💡 Hint
Think about how the last node connects in a circular singly linked list.
✗ Incorrect
In a circular singly linked list, the last node points back to the head, enabling continuous traversal without null checks.