C++ Solution O(nlogn) solution by assigning ids to serializations
\nclass Solution {\n    struct Node {\n        string val;\n        bool skip = false;\n        unordered_map<string, Node*> next;\n        Node() = default;\n 
```\nclass Solution {\n    struct Node {\n        string val;\n        bool skip = false;\n        unordered_map<string, Node*> next;\n        Node() = default;\n        Node(string v) : val{move(v)} {};\n    }; \n    unordered_map<string, pair<int, Node*>> tree_map;\n    unordered_map<string, Node*> content_map;\n    int count = 1;\n    \n    int dfs(Node* n) {\n        vector<int> ids;\n        for(auto p : n->next) ids.push_back(dfs(p.second));\n        sort(ids.begin(), ids.end());\n        string tree_key = n->val;\n        string content_key;\n        for(auto id : ids) content_key.append("," + to_string(id));\n        tree_key.append(content_key);\n        auto [it, ins] = tree_map.try_emplace(tree_key, make_pair(count, n));\n        if(ins) ++count;\n        if(!ids.empty()) {\n            auto [it2, ins2] = content_map.try_emplace(content_key, n);\n            if(!ins2) {\n                n->skip = true;\n                it2->second->skip = true;\n            }\n        }\n        return it->second.first;\n    }\n    vector<vector<string>> ans;\n    void get_paths(Node* n, vector<string>& path) {\n        if(n->skip) return;\n        path.push_back(move(n->val));\n        ans.push_back(path);\n        for(auto p : n->next) get_paths(p.second, path);\n        path.pop_back();\n    }\npublic:\n    vector<vector<string>> deleteDuplicateFolder(vector<vector<string>>& paths) {\n        // create the tree \n        auto root = new Node();\n        for(auto v : paths) {\n            auto curr = root;\n            int i = 0;\n            for(auto k : v) {\n                if(curr->next.find(k) == curr->next.end()) curr->next[k] = new Node(k);\n                curr = curr->next[k];\n            }\n        }\n        dfs(root);\n        vector<string> path;\n        for(auto p : root->next) get_paths(p.second, path);\n        return ans;\n    }\n};\n\n```
[]