Difficult Question mostly from volume of code
\nclass Solution {\n    HashMap<String, Set<Trie>> dup = new HashMap<>();\n    List<List<String>> cleanedPaths = new ArrayList<>();\n\n    class Trie {\n\n     
```\nclass Solution {\n    HashMap<String, Set<Trie>> dup = new HashMap<>();\n    List<List<String>> cleanedPaths = new ArrayList<>();\n\n    class Trie {\n\n        public TreeMap<String, Trie> map = new TreeMap<>();\n        public boolean leaf = false;\n        public String name;\n        public Trie parent;\n        public boolean delete = false;\n\n        @Override\n        public String toString() {\n            return name;\n        }\n\n        public Trie(String name, Trie parent) {\n            this.name = name;\n            this.parent = parent;\n        }\n\n        void insert(List<String> path, int idx) {\n            if (idx >= path.size()) {\n                this.leaf = true;\n                return;\n            }\n            if (!map.containsKey(path.get(idx))) {\n                map.put(path.get(idx), new Trie(path.get(idx), this));\n            }\n            map.get(path.get(idx)).insert(path, idx + 1);\n        }\n    }\n\n    String traverse(Trie root) {\n        StringBuilder hash = new StringBuilder();\n        for (String key : root.map.keySet()) {\n            String curr = traverse(root.map.get(key));\n            hash.append(curr).append("#");\n        }\n        if (root.map.keySet().size() != 0) {\n            if (!dup.containsKey(hash.toString())) {\n                dup.put(hash.toString(), new HashSet<>());\n            }\n            dup.get(hash.toString()).add(root);\n        }\n        return "/" + root.name + hash;\n    }\n\n    public List<List<String>> deleteDuplicateFolder(List<List<String>> paths) {\n        Trie t = new Trie("", null);\n        for (List<String> folder : paths) {\n            t.insert(folder, 0);\n        }\n        traverse(t);\n        for (String key : dup.keySet()) {\n            if (dup.get(key).size() > 1) {\n                Set<Trie> set = dup.get(key);\n                for (Trie trie : set) {\n                    if (trie.parent != null) {\n                        trie.parent.map.remove(trie.name);\n                    }\n                }\n            }\n        }\n        allPaths(t, new ArrayList<>());\n        return cleanedPaths;\n    }\n\n    private void allPaths(Trie node, List<String> path) {\n        if (!node.name.equals("")) {\n            path.add(node.name);\n        }\n        if (!path.isEmpty()) {\n            cleanedPaths.add(new ArrayList<>(path));\n        }\n        for (String child : node.map.keySet()) {\n            allPaths(node.map.get(child), path);\n        }\n        if (path.size() > 0) {\n            path.remove(path.size() - 1);\n        }\n    }\n}\n```
[]