Java - Two Pointers - 0 ms
O(n) time, O(1) space (where n is the total number of nodes in the linked list).\n\nWe traverse until we find a node with a child - let\'s call it parent. From 
O(n) time, O(1) space (where n is the total number of nodes in the linked list).\n\nWe traverse until we find a node with a child - let\'s call it parent. From here, we set up a few variables: the parent\'s original next node, and the parent\'s child. Additionally, we traverse the child list to find its last node. First, we clear the parent\'s child pointer. Now it\'s just a matter of joining three lists, with the second spliced in-between the first and the third. We take care to check that our third list is not null. And finally, we repeat this process until we\'re at the end of the list.\n\n```\npublic Node flatten(Node head) {\n        Node curr = head;\n        \n        while (curr != null) {\n            if (curr.child == null) {\n                curr = curr.next;\n            } else {\n                Node parent = curr;\n                Node parentNext = parent.next;\n                Node child = curr.child;\n                Node childLast = child;\n                parent.child = null;\n                while (childLast != null && childLast.next != null) {\n                    childLast = childLast.next;\n                }\n                parent.next = child;\n                child.prev = parent;\n                childLast.next = parentNext;\n                if (parentNext != null) {\n                    parentNext.prev = childLast;\n                }\n            }\n        }\n        \n        return head;\n    }\n```\n\nI think we could optimize this solution in the case where the child list has its own child list and splice that list in before continuing with the original.
['Two Pointers', 'Java']