Challenge - 5 Problems
Circular Singly Linked List Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of Circular Singly Linked List after Insertions
What is the printed state of the circular singly linked list after inserting nodes with values 10, 20, and 30 in that order?
DSA Go
package main import "fmt" type Node struct { data int next *Node } type CircularSinglyLinkedList struct { head *Node } func (list *CircularSinglyLinkedList) Insert(value int) { newNode := &Node{data: value} if list.head == nil { list.head = newNode newNode.next = newNode return } temp := list.head for temp.next != list.head { temp = temp.next } temp.next = newNode newNode.next = list.head } func (list *CircularSinglyLinkedList) Print() { if list.head == nil { fmt.Println("List is empty") return } temp := list.head for { fmt.Printf("%d -> ", temp.data) temp = temp.next if temp == list.head { break } } fmt.Println("(head)") } func main() { list := CircularSinglyLinkedList{} list.Insert(10) list.Insert(20) list.Insert(30) list.Print() }
Attempts:
2 left
💡 Hint
Remember that each new node is added at the end and points back to the head.
✗ Incorrect
Nodes are inserted at the end. After inserting 10, 20, and 30, the list prints in insertion order ending back at head.
❓ Predict Output
intermediateOutput after Deleting Head Node in Circular Singly Linked List
Given a circular singly linked list with nodes 5 -> 15 -> 25 -> (head), what is the printed list after deleting the head node (value 5)?
DSA Go
package main import "fmt" type Node struct { data int next *Node } type CircularSinglyLinkedList struct { head *Node } func (list *CircularSinglyLinkedList) Insert(value int) { newNode := &Node{data: value} if list.head == nil { list.head = newNode newNode.next = newNode return } temp := list.head for temp.next != list.head { temp = temp.next } temp.next = newNode newNode.next = list.head } func (list *CircularSinglyLinkedList) DeleteHead() { if list.head == nil { return } if list.head.next == list.head { list.head = nil return } temp := list.head for temp.next != list.head { temp = temp.next } temp.next = list.head.next list.head = list.head.next } func (list *CircularSinglyLinkedList) Print() { if list.head == nil { fmt.Println("List is empty") return } temp := list.head for { fmt.Printf("%d -> ", temp.data) temp = temp.next if temp == list.head { break } } fmt.Println("(head)") } func main() { list := CircularSinglyLinkedList{} list.Insert(5) list.Insert(15) list.Insert(25) list.DeleteHead() list.Print() }
Attempts:
2 left
💡 Hint
Deleting head means the second node becomes the new head.
✗ Incorrect
After deleting the head (5), the new head is 15 and the list loops back to it.
🔧 Debug
advancedIdentify the Bug in Circular Singly Linked List Insertion
What error will occur when running this insertion code for a circular singly linked list?
DSA Go
func (list *CircularSinglyLinkedList) Insert(value int) { newNode := &Node{data: value} if list.head == nil { list.head = newNode newNode.next = nil return } temp := list.head for temp.next != list.head { temp = temp.next } temp.next = newNode newNode.next = list.head }
Attempts:
2 left
💡 Hint
Check what happens when the list has only one node.
✗ Incorrect
Setting newNode.next to nil breaks the circular link, making the list non-circular.
❓ Predict Output
advancedOutput after Traversing Circular Singly Linked List with One Node
What is the output when printing a circular singly linked list with a single node containing value 42?
DSA Go
package main import "fmt" type Node struct { data int next *Node } type CircularSinglyLinkedList struct { head *Node } func (list *CircularSinglyLinkedList) Insert(value int) { newNode := &Node{data: value} if list.head == nil { list.head = newNode newNode.next = newNode return } temp := list.head for temp.next != list.head { temp = temp.next } temp.next = newNode newNode.next = list.head } func (list *CircularSinglyLinkedList) Print() { if list.head == nil { fmt.Println("List is empty") return } temp := list.head for { fmt.Printf("%d -> ", temp.data) temp = temp.next if temp == list.head { break } } fmt.Println("(head)") } func main() { list := CircularSinglyLinkedList{} list.Insert(42) list.Print() }
Attempts:
2 left
💡 Hint
A single node points to itself in a circular list.
✗ Incorrect
The single node points back to itself, so it prints once then stops.
🧠 Conceptual
expertNumber of Nodes in Circular Singly Linked List after Multiple Insertions and Deletions
Starting with an empty circular singly linked list, you insert nodes with values 1, 2, 3, 4, and 5 in order. Then you delete the head node twice. How many nodes remain in the list?
Attempts:
2 left
💡 Hint
Each deletion removes one node from the list.
✗ Incorrect
After inserting 5 nodes and deleting head twice, 3 nodes remain.
