Flatten a Multilevel Doubly Linked List || Java O(N) Solution using Recursion
\npublic Node flatten(Node head) {\n        helper(head);\n        return head;\n    }\n    public Node helper(Node node){\n        while(node != null){\n      
```\npublic Node flatten(Node head) {\n        helper(head);\n        return head;\n    }\n    public Node helper(Node node){\n        while(node != null){\n            if(node.child != null){     // If the current node has a child\n                Node stored = node.next;       // we store its old next node\n                Node childLast = helper(node.child);   //and make a recursive call to find the last child in the multilevel list\n                \n                node.next = node.child;  // Make the child of the current node its next node\n                node.child.prev = node;  // And similarly link the prev of the new next to the current node \n                \n                if(stored != null){\n                    childLast.next = stored;  // Make the stored node the last node by making it the next node of the childlast node\n                    stored.prev = childLast;\n                }\n                node.child = null;  // Important: Setting the child to null to avoid errors\n                node = childLast;  // To avoid reiterating over the entire list again, we directly jump to the childlast node and continue\n            }else{\n                if(node.next == null){\n                    break;\n                }\n                node = node.next;  // if the current node doesn\'t have a child, keep iterating until you find a node with a child\n            }\n        }\n        return node;\n    }\n```
[]