Challenge - 5 Problems
Linked List Traversal Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of Traversing a Linked List
What is the printed output of the following Go code that traverses and prints a singly linked list?
DSA Go
package main import "fmt" type Node struct { value int next *Node } func main() { head := &Node{value: 1} head.next = &Node{value: 2} head.next.next = &Node{value: 3} current := head for current != nil { fmt.Printf("%d -> ", current.value) current = current.next } fmt.Print("null\n") }
Attempts:
2 left
💡 Hint
Trace the loop from head to the end, printing each node's value.
✗ Incorrect
The code starts at the head node with value 1 and moves through each next node, printing values in order: 1, then 2, then 3, followed by 'null' to indicate the end.
❓ Predict Output
intermediateDetecting Output After Modifying Linked List
What is the output after running this Go code that modifies a linked list before printing?
DSA Go
package main import "fmt" type Node struct { value int next *Node } func main() { head := &Node{value: 10} head.next = &Node{value: 20} head.next.next = &Node{value: 30} head.next = head.next.next current := head for current != nil { fmt.Printf("%d -> ", current.value) current = current.next } fmt.Print("null\n") }
Attempts:
2 left
💡 Hint
Look at how the next pointer of the head node is changed before printing.
✗ Incorrect
The code skips the node with value 20 by pointing head.next to head.next.next, so the list becomes 10 -> 30 -> null.
🔧 Debug
advancedIdentify the Error in Linked List Traversal
What error does this Go code produce when trying to traverse and print a linked list?
DSA Go
package main import "fmt" type Node struct { value int next *Node } func main() { head := &Node{value: 5} head.next = &Node{value: 10} current := head for current.next != nil { fmt.Printf("%d -> ", current.value) current = current.next } fmt.Print("null\n") }
Attempts:
2 left
💡 Hint
Check the loop condition and what nodes get printed inside the loop.
✗ Incorrect
The loop stops when current.next is nil, so it does not print the last node's value (10). No panic or syntax error occurs.
❓ Predict Output
advancedOutput of Recursive Linked List Print
What is the output of this Go code that prints a linked list recursively?
DSA Go
package main import "fmt" type Node struct { value int next *Node } func printList(node *Node) { if node == nil { fmt.Print("null\n") return } fmt.Printf("%d -> ", node.value) printList(node.next) } func main() { head := &Node{value: 7} head.next = &Node{value: 14} head.next.next = &Node{value: 21} printList(head) }
Attempts:
2 left
💡 Hint
Follow the recursive calls printing each node's value before the next call.
✗ Incorrect
The function prints the current node's value then calls itself on the next node, printing all values in order followed by 'null'.
🧠 Conceptual
expertNumber of Nodes After Multiple Insertions
Starting with an empty linked list, the following insertions happen in order: insert 1 at head, insert 2 at head, insert 3 at tail, insert 4 at tail. How many nodes does the list contain after these operations?
Attempts:
2 left
💡 Hint
Count each insertion carefully, noting head and tail insertions add nodes.
✗ Incorrect
Each insertion adds one node. Two insertions at head and two at tail total 4 nodes.
