Question Bank

Linked List Trace and Pointers

Difficulty: Medium

Four mid-level prompts on in-place reversal, node swapping, and the trickiest pointer bug. Mixes implementation and step-by-step trace.

Question Bank
/

Linked List Trace and Pointers

Linked List Trace and Pointers

Four mid-level prompts on in-place reversal, node swapping, and the trickiest pointer bug. Mixes implementation and step-by-step trace.

Question Bank
Medium
JavaScript
4 questions
linked-list
pointers
data-structures
interview-prep

340 views

4

Implement reverseList(head) that reverses a singly linked list in place and returns the new head. Use the iterative three-pointer pattern.

Examples

Example 1:

Input: head = 1 -> 2 -> 3 -> null
Output: new head with traversal yielding [3, 2, 1]
Explanation: Maintain prev = null and curr = head. Each step saves next = curr.next, redirects curr.next = prev, then advances prev and curr. The save step is what prevents losing the rest of the list. O(n) time, O(1) space.