Why does reversing a singly linked list run in O(n) time and O(1) space, and what state do you have to track to avoid losing the rest of the list?

technical-conceptual · Mid level · software-engineering

What the interviewer is really asking

Probes whether the candidate can drive the iterative pointer-reversal in place, name the three-pointer state it requires, and contrast it with the recursive version's space cost rather than reciting a memorized template.

What to say

What to avoid

Example answers

Strong: I needed to reverse an in-memory event chain without allocating, so I used the three-pointer iterative walk: save next, point curr back at prev, slide both forward. One pass, no allocation, and I verified the new head was the old tail. I picked iterative specifically because the chains could be very long and recursion would have risked a stack overflow.

Weak: I'd loop through and set each node's next to the previous node — point it backward and move on.

Want questions matched to your role? Paste a job title, job description, or CV and get a personalized set, or go Pro to unlock the full bank.