DSA interview question
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.
DNode* reverseDLL(DNode* head); // returns the new head (the old tail)
| Input | Output | Explanation |
|---|---|---|
1 <-> 2 <-> 3 <-> 4 | 4 <-> 3 <-> 2 <-> 1 | |
1 <-> 2 | 2 <-> 1 | |
7 | 7 | A single node is unchanged |
(empty) | (empty) |
(Confirm: reverse the links, not the values; the backward traversal of the result must be the original order.)
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 interviewAll 474 dsa interview questions
DSA mock interviews · System design interview questions · Free mock interview practice · Browse interviewers · Sign in