Junior
Detailed answer
Linked Lists
DSA & Coding Interviews
How do you reverse a linked list (iterative and recursive)?
Short answer: Iterative: three pointers prev, curr, next. Flip curr.next to prev and advance. Recursive: reverse the rest, then point head.next.next = head and head.next = null. Iterative is usually preferred in interviews for O(1) stack space.
Complexity
Time O(n). Iterative space O(1); recursive space O(n) call stack.
Edge cases to mention
- Empty list
- Single node
- Cycle (clarify — usually assume none)
Common follow-ups
- Reverse nodes in k-group
- Reverse between left and right
Draw 3 nodes on the whiteboard before coding — it prevents pointer bugs.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png