Easy solution 99% fast [C++]
\nclass Solution {\npublic:\n  \n    vector < Node > v;\n  \n    void dfs(Node head){\n      v.push_back(head);\n      if(head -> child != nullptr){\n        df
\nclass Solution {\npublic:\n  \n    vector < Node* > v;\n  \n    void dfs(Node* head){\n      v.push_back(head);\n      if(head -> child != nullptr){\n        dfs(head -> child);\n      }\n      if(head -> next != nullptr){\n        dfs(head -> next);\n      }\n    }\n  \n    Node* flatten(Node* head) {\n        \n      if(head == nullptr){\n        return head;\n      }\n      \n      dfs(head);\n      \n      if(v.size() == 1){\n        v[0] -> prev = NULL;\n        v[0] -> child = NULL;\n        v[0] -> next = NULL;\n        return head;\n      }\n      \n      for(int i = 0; i < v.size(); i++){\n        if(i == 0){\n          v[i] -> prev = NULL;\n          v[i] -> child = NULL;\n          v[i] -> next = v[i + 1];\n        }\n        else if(i == v.size() - 1){\n          v[i] -> prev = v[i - 1];\n          v[i] -> child = NULL;\n          v[i] -> next = NULL;\n        }\n        else{\n          v[i] -> prev = v[i - 1];\n          v[i] -> child = NULL;\n          v[i] -> next = v[i + 1];\n        }\n      }\n      \n      return head;\n    }\n};
[]