Challenge - 5 Problems
Doubly Linked List Deletion Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput after deleting the first node from a doubly linked list
What is the printed state of the doubly linked list after deleting the first node?
DSA Go
package main import "fmt" type Node struct { data int prev *Node next *Node } type DoublyLinkedList struct { head *Node } func (dll *DoublyLinkedList) InsertEnd(data int) { newNode := &Node{data: data} if dll.head == nil { dll.head = newNode return } current := dll.head for current.next != nil { current = current.next } current.next = newNode newNode.prev = current } func (dll *DoublyLinkedList) DeleteBeginning() { if dll.head == nil { return } if dll.head.next == nil { dll.head = nil return } dll.head = dll.head.next dll.head.prev = nil } func (dll *DoublyLinkedList) PrintList() { current := dll.head for current != nil { fmt.Printf("%d <-> ", current.data) current = current.next } fmt.Println("null") } func main() { dll := DoublyLinkedList{} dll.InsertEnd(10) dll.InsertEnd(20) dll.InsertEnd(30) dll.DeleteBeginning() dll.PrintList() }
Attempts:
2 left
💡 Hint
Deleting the first node means the head moves to the next node.
✗ Incorrect
Initially, the list is 10 <-> 20 <-> 30 <-> null.
After deleting the first node (10), the head points to 20.
So the list becomes 20 <-> 30 <-> null.
❓ Predict Output
intermediateResult after deleting from a single-node doubly linked list
What is the output after deleting the first node from a doubly linked list with only one node?
DSA Go
package main import "fmt" type Node struct { data int prev *Node next *Node } type DoublyLinkedList struct { head *Node } func (dll *DoublyLinkedList) InsertEnd(data int) { newNode := &Node{data: data} if dll.head == nil { dll.head = newNode return } current := dll.head for current.next != nil { current = current.next } current.next = newNode newNode.prev = current } func (dll *DoublyLinkedList) DeleteBeginning() { if dll.head == nil { return } if dll.head.next == nil { dll.head = nil return } dll.head = dll.head.next dll.head.prev = nil } func (dll *DoublyLinkedList) PrintList() { current := dll.head for current != nil { fmt.Printf("%d <-> ", current.data) current = current.next } fmt.Println("null") } func main() { dll := DoublyLinkedList{} dll.InsertEnd(100) dll.DeleteBeginning() dll.PrintList() }
Attempts:
2 left
💡 Hint
Deleting the only node should leave the list empty.
✗ Incorrect
With only one node (100), deleting the beginning sets head to nil.
Printing the list shows null.
🔧 Debug
advancedIdentify the error in DeleteBeginning method
What error will this code produce when deleting from an empty doubly linked list?
DSA Go
func (dll *DoublyLinkedList) DeleteBeginning() {
dll.head = dll.head.next
dll.head.prev = nil
}Attempts:
2 left
💡 Hint
Check what happens if dll.head is nil before accessing dll.head.next.
✗ Incorrect
If dll.head is nil, accessing dll.head.next causes a runtime nil pointer dereference error.
🧠 Conceptual
advancedEffect of DeleteBeginning on doubly linked list pointers
After deleting the first node from a doubly linked list, which pointers must be updated to maintain list integrity?
Attempts:
2 left
💡 Hint
Deleting from beginning affects the head and its previous pointer.
✗ Incorrect
Deleting the first node means head moves to the next node.
The new head's prev pointer must be nil to indicate start of list.
🚀 Application
expertNumber of nodes after multiple deletions from beginning
Given a doubly linked list with nodes 5 <-> 15 <-> 25 <-> 35 <-> 45 <-> null, after deleting from the beginning three times, how many nodes remain?
Attempts:
2 left
💡 Hint
Each deletion removes one node from the start.
✗ Incorrect
Starting with 5 nodes, deleting 3 nodes from beginning leaves 2 nodes.
