PPractick

DSA interview question

Reverse a Doubly Linked List

Medium · Data structures · Topics: linkedlist, doubly linkedlist

The problem

A playlist app stores songs in a doubly linked list and offers a "reverse order" button. In a doubly linked list, reversing is surprisingly simple: every node already knows both neighbours, so reversing the list just means swapping each node's prev and next pointers. The old tail becomes the new head. No extra list and no values moved, just one pass that flips every link.

Example: 1 <-> 2 <-> 3 <-> 4 → 4 <-> 3 <-> 2 <-> 1.

Function signature

DNode* reverseDLL(DNode* head);  // returns the new head (the old tail)

Test cases

InputOutputExplanation
1 <-> 2 <-> 3 <-> 44 <-> 3 <-> 2 <-> 1
1 <-> 22 <-> 1
77A single node is unchanged
(empty)(empty)

(Confirm: reverse the links, not the values; the backward traversal of the result must be the original order.)

How interviewers phrase it

Clarifying questions to ask

  1. Should I reverse the links, or is swapping values acceptable? (Links is the intended answer.)
  2. Should the function return the new head?
  3. Is there a tail pointer to update too?

Follow-ups to expect

  1. "Why is swapping prev and next enough?"
  2. "How do you move to the next node after swapping?"
  3. "Why not just swap values from both ends?"
  4. "How does this differ from a singly linked list?"
  5. "Complexity?"

Practise questions like this with a real engineer

On Practick another engineer interviews you live for 60 minutes on a question from this bank. They have the full interviewer guide beside the call: the expected answer to every follow-up, hints to give if you stall, and a scoring rubric. You get the model solution once the session settles. It is free: interview someone for an hour and you have earned your own.

Book a free mock interview

Related questions

All 474 dsa interview questions

DSA mock interviews · System design interview questions · Free mock interview practice · Browse interviewers · Sign in