Java Recursive Solution
\n    public Node flatten(Node head) {\n    \tflattentail(head);\n    \treturn head;\n    }\n\n    // flattentail: flatten the node "head" and return the tail i
```\n    public Node flatten(Node head) {\n    \tflattentail(head);\n    \treturn head;\n    }\n\n    // flattentail: flatten the node "head" and return the tail in its child (if exists)\n    // the tail means the last node after flattening "head"\n\n    // Five situations:\n    // 1. null - no need to flatten, just return it\n    // 2. no child, no next - no need to flatten, it is the last element, just return it\n    // 3. no child, next - no need to flatten, go next\n    // 4. child, no next - flatten the child and done\n    // 5. child, next - flatten the child, connect it with the next, go next\n\n    private Node flattentail(Node head) {\n    \tif (head == null) return head; // CASE 1\n    \tif (head.child == null) {\n    \t\tif (head.next == null) return head; // CASE 2\n    \t\treturn flattentail(head.next); // CASE 3\n    \t}\n    \telse {\n    \t\tNode child = head.child;  \n    \t\thead.child = null;\n    \t\tNode next = head.next;\n    \t\tNode childtail = flattentail(child);\n    \t\thead.next = child;\n    \t\tchild.prev = head;  \n\t\t\tif (next != null) { // CASE 5\n\t\t\t\tchildtail.next = next;\n\t\t\t\tnext.prev = childtail;\n\t\t\t\treturn flattentail(next);\n\t\t\t}\n            return childtail; // CASE 4\n    \t}\t   \t\n    }\n```
[]