Challenge - 5 Problems
Linked List Pop Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateWhat is the output after popping the head node?
Consider a singly linked list with nodes containing values 10 -> 20 -> 30 -> null. The pop operation removes the head node and returns the new head. What is the printed state of the list after popping once?
DSA Go
package main import "fmt" type Node struct { Val int Next *Node } func pop(head *Node) *Node { if head == nil { return nil } return head.Next } func printList(head *Node) string { result := "" for head != nil { result += fmt.Sprintf("%d -> ", head.Val) head = head.Next } result += "null" return result } func main() { head := &Node{Val: 10, Next: &Node{Val: 20, Next: &Node{Val: 30}}} head = pop(head) fmt.Println(printList(head)) }
Attempts:
2 left
💡 Hint
Popping removes the first node and returns the next node as the new head.
✗ Incorrect
The pop function removes the head node (value 10) and returns the next node (value 20) as the new head. The list after popping is 20 -> 30 -> null.
❓ Predict Output
intermediateWhat happens when popping an empty list?
Given an empty linked list (head is nil), what is the output of the pop operation and the printed list?
DSA Go
package main import "fmt" type Node struct { Val int Next *Node } func pop(head *Node) *Node { if head == nil { return nil } return head.Next } func printList(head *Node) string { result := "" for head != nil { result += fmt.Sprintf("%d -> ", head.Val) head = head.Next } result += "null" return result } func main() { var head *Node = nil head = pop(head) fmt.Println(printList(head)) }
Attempts:
2 left
💡 Hint
Popping an empty list returns nil, so printing shows null.
✗ Incorrect
Since the list is empty (head is nil), popping returns nil. Printing the list shows null.
❓ Predict Output
advancedWhat is the output after popping twice from a 3-node list?
Given a linked list 5 -> 15 -> 25 -> null, after popping twice, what is the printed list?
DSA Go
package main import "fmt" type Node struct { Val int Next *Node } func pop(head *Node) *Node { if head == nil { return nil } return head.Next } func printList(head *Node) string { result := "" for head != nil { result += fmt.Sprintf("%d -> ", head.Val) head = head.Next } result += "null" return result } func main() { head := &Node{Val: 5, Next: &Node{Val: 15, Next: &Node{Val: 25}}} head = pop(head) head = pop(head) fmt.Println(printList(head)) }
Attempts:
2 left
💡 Hint
Each pop removes the head node, so after two pops, the head points to the third node.
✗ Incorrect
First pop removes 5, second pop removes 15, so the list starts at 25 -> null.
❓ Predict Output
advancedWhat error occurs if pop tries to access Next of nil?
What happens if the pop function is called with a nil head and tries to access head.Next without checking if head is nil?
DSA Go
package main type Node struct { Val int Next *Node } func pop(head *Node) *Node { return head.Next } func main() { var head *Node = nil head = pop(head) }
Attempts:
2 left
💡 Hint
Accessing a field of nil pointer causes a runtime panic in Go.
✗ Incorrect
Since head is nil, accessing head.Next causes a runtime panic due to nil pointer dereference.
🧠 Conceptual
expertWhat is the time complexity of popping the head node in a singly linked list?
Consider a singly linked list with n nodes. What is the time complexity of the pop operation that removes the head node?
Attempts:
2 left
💡 Hint
Popping the head only changes the head pointer to the next node.
✗ Incorrect
Removing the head node requires only updating the head pointer, which is a constant time operation O(1).
