Microsoft Interview Question

Reverse a double linked list

Interview Answer

Anonymous

Sep 23, 2021

swap previous and next pointers for all nodes, change previous of the head (or start) and change the head pointer in the end. // swapping pointer let reverseDLL = (head) => { let temp = null; let current = head; while(current){ temp = current.prev; current.prev = current.next; current.next = temp; current = current.prev; } if (temp != null) { head = temp.prev; } }