python || O(1) space || iterative || detailed explanation || very fast
\n"""\n# Definition for a Node.\nclass Node:\n    def __init__(self, val, prev, next, child):\n        self.val = val\n        self.prev = prev\n        self.ne
```\n"""\n# Definition for a Node.\nclass Node:\n    def __init__(self, val, prev, next, child):\n        self.val = val\n        self.prev = prev\n        self.next = next\n        self.child = child\n"""\n\nclass Solution:\n    def flatten(self, head: \'Optional[Node]\') -> \'Optional[Node]\':    \n        node = head\n        while node:\n            if node.child: # If there is a child travel to last node of the child\n                child = node.child\n                while child.next:\n                    child = child.next\n                child.next = node.next # Update the next of child to the the next of the current node\n                if node.next: # update the prev of the next node to chile to make it valid doubly linked list\n                    node.next.prev = child\n                node.next = node.child # Update the child to become the next of the current\n                node.next.prev = node # update the prev of the next node to chile to make it valid doubly linked list\n                node.child = None # Make the child of the current node None to fulfill the requirements\n            node = node.next\n        return head\n\n# time and space complexity\n# time: O(n)\n# space: O(1)\n```
['Iterator', 'Python']