Java optimized solution (beast 100%)
Intuition\nTo store full info about folder\'s content in a huge string and use HashMap to check for duplicates\n Describe your first thoughts on how to solve th
# Intuition\nTo store full info about folder\'s content in a **huge** string and use HashMap to check for duplicates\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nTo be efficient, we sort incoming array  by path string length, and then iterate through it forward (to make sure all parent folders already iterated before) or backward (to make sure all children folders are already iterated before).\n\nWe use TreeMap to store children - although I haven\'t noticed any difference in peformance.\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    class Node {\n        Map<String, Node> subNodes = new TreeMap<>();\n\n        String content = "";\n\n        boolean remove = false;\n\n        void markRemove() {\n            if (remove) {\n                return;\n            }\n            remove = true;\n            if (subNodes != null) {\n                for (Node value : subNodes.values()) {\n                    value.markRemove();\n                }\n            }\n        }\n    }\n\n    public List<List<String>> deleteDuplicateFolder(List<List<String>> paths) {\n        paths.sort(Comparator.comparingInt(List::size));\n        List<Node> nodes = new ArrayList<>(paths.size());\n        Node rootNode = new Node();\n        for (List<String> pathList : paths) {\n            Node current = rootNode;\n            int last = pathList.size() - 1;\n            for (int i = 0; i < last; i++) {\n                String s = pathList.get(i);\n                current = current.subNodes.get(s);\n            }\n            String name = pathList.get(last);\n            Node node = new Node();\n            current.subNodes.put(name, node);\n            nodes.add(node);\n        }\n        StringBuilder content = new StringBuilder();\n        Map<String, Node> nodeByContent = new HashMap<>();\n        for (int i = nodes.size() - 1; i >= 0; i--) {\n            Node node = nodes.get(i);\n            if (node.subNodes.isEmpty()) {\n                continue;\n            }\n            for (Map.Entry<String, Node> entry : node.subNodes.entrySet()) {\n                content.append(entry.getKey()).append(\'{\').append(entry.getValue().content).append(\'}\');\n            }\n            node.content = content.toString();\n            content.delete(0, content.length());\n            Node similar = nodeByContent.putIfAbsent(node.content, node);\n            if (similar != null) {\n                node.markRemove();\n                similar.markRemove();\n            }\n        }\n        List<List<String>> ans = new ArrayList<>();\n        for (int i = 0; i < paths.size(); i++) {\n            if (!nodes.get(i).remove) {\n                ans.add(paths.get(i));\n            }\n        }\n        return ans;\n    }\n}\n```
['Java']