0ms solution || beats 100% || easy to understand || O(n) time complexity || O(1) space complexity
Intuition\n Describe your first thoughts on how to solve this problem. Intuition is to insert all child nodes between parent node and parent->next node and the 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->Intuition is to insert all child nodes between parent node and parent->next node and the again check for child nodes from parent node\n\n# Complexity\n- Time complexity:  O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n![image.png](https://assets.leetcode.com/users/images/977c6bc8-7a99-483d-83d7-752625e01888_1720494954.778931.png)\n\n\n# Code\n```\n/*\n// Definition for a Node.\nclass Node {\npublic:\n    int val;\n    Node* prev;\n    Node* next;\n    Node* child;\n};\n*/\n\nclass Solution {\npublic:\n    Node* flatten(Node* head) {\n        Node* temp=head;\n\n        while(temp!=NULL){\n            if(temp->child!=NULL){\n                Node* forward=temp->next;\n                Node* temp_child=temp;\n                temp=temp->child;\n                temp_child->child=NULL;\n                temp_child->next=temp;\n                temp->prev=temp_child;\n\n                while(temp->next!=NULL){\n                    temp=temp->next;\n                }\n\n                temp->next=forward;\n                if(forward!=NULL) forward->prev=temp;\n                temp=temp_child;\n            }\n            temp=temp->next;\n        }\n\n        return head;\n    }\n};\n```\n\n![image.png](https://assets.leetcode.com/users/images/5b4d2862-0405-4a61-b675-09618e3c80e4_1717773094.7361126.jpeg)
['Linked List', 'C++']