Linked List Go
Fast recall
Quick revision
Core answer
Whether you understand Linked List Go beyond memorized syntax.
Giving a definition without explaining a practical trade-off.
Connect the concept to a small production example and state its complexity or failure mode.
Interview-ready guide
Interview answer
The type and reversal, executed:
type Node struct {
Val int
Next *Node
}
func reverseList(head *Node) *Node {
var prev *Node // nil — the future tail
curr := head
for curr != nil {
next := curr.Next // save forward pointer
curr.Next = prev // reverse THIS node
prev = curr // advance prev
curr = next // advance curr
}
return prev // prev is the new head
}
// 1→2→3 becomes 3→2→1 — verifiedThe three-variable pattern: prev (the reversed part's head), curr (the node being reversed), next (the temporary holding the forward pointer before we overwrite it). Each iteration: save next, flip curr's pointer, advance both.
The invariants: prev points to a correctly-reversed list of everything before curr; curr points to the unreversed remainder. The loop ends when curr is nil — prev holds the entire reversed list.
Why a self-referential type works: a struct can't contain ITSELF by value (infinite size) — a *Node field is a fixed-size pointer, so the recursion is broken by indirection. That's every linked structure in Go.
The Go slice alternative: for simple stacks/queues, a slice is almost always better (contiguous memory, append/POP). The linked list's genuine use: interview correctness, embedded/OS-style intrusive lists, and when you need O(1) removal from the middle (a map to node pointers).
Linked List Go
Direct Answer
type Node struct { Val int; Next *Node } — the self-referential pointer type. Reversal: three variables (prev, curr, next), one loop. Verified: 1→2→3 becomes 3→2→1.
Deep Dive & Architecture
The pointer mechanics, one layer down: curr.Next = prev is one store — reversing a node is a single pointer write. The total cost is O(n) — one loop, no allocation. Space: O(1) — the three variables, regardless of list length. That's the property that makes in-place reversal the canonical interview question: trivial invariant, trivial loop, and every line must be right.
The recursive alternative and its trade: recurse to the tail, then flip on the way back (head.Next.Next = head; head.Next = nil). Same O(n) time, but O(n) stack space — the loop version is strictly better for the general case. The recursive version maps cleanly to the problem's structure (the reversed tail is the subproblem), which is why interviews ask for both.
The Go-specific pattern: the singly-linked list with methods (func (n *Node) Len() int, func (n *Node) String() string) — the type reads as a package-level utility. The container/list package (doubly-linked) exists for when you genuinely need O(1) insertion/removal — rare in application code.
Common Mistakes & Pitfalls
Giving a definition without explaining a practical trade-off.
Check your understanding
Answer these without looking back at the article.
- When would you use Linked List Go in a real project?
- How would you compare Linked List Go with an alternative?
- What is a common mistake when using Linked List Go?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.