Problem Statement

Pattern:


Solution

public static Node reverseDLL(Node  head)
{
    //Your code here
    Node prev = null;
    
    while (head != null) {
        // store next
        Node next = head.next;
        
        // swap prev & next
        head.next = prev;
        head.prev = next;
                    
        // increment prev & head                        
        prev = head;
        head = next;
    }
    return prev;
    // return last node
}

Notes