Python3. Hash every subtree
\nclass Solution:\n    def deleteDuplicateFolder(self, paths: List[List[str]]) -> List[List[str]]:\n        tree = {}\n        child_hashes = defaultdict(list)\
```\nclass Solution:\n    def deleteDuplicateFolder(self, paths: List[List[str]]) -> List[List[str]]:\n        tree = {}\n        child_hashes = defaultdict(list)\n\t\t\n\t\t# build directories tree\n        for path in paths:\n            node = tree\n            for folder in path:\n                if folder not in node:\n                    node[folder] = {}\n                node = node[folder]\n        \n\t\t# iterate all children in sorted order and hash them as tuple,\n\t\t# then add current node key to hash and return\n        def dfs(node, node_key, parent):\n            child_tuple = tuple(dfs(node[key], key, node) for key in sorted(node.keys()))\n            child_hash = hash(child_tuple)\n            if child_tuple:\n                child_hashes[child_hash].append((parent, node_key))\n            return hash((child_hash, node_key))\n\n        dfs(tree, None, None)\n\n\t\t# find all subtree with the same hash and delete them from the tree\n        for duplicates in child_hashes.values():\n            if len(duplicates) > 1:\n                for parent, node_key in duplicates:\n                    del parent[node_key]\n\n\t\t# simple dfs to collect all "root -> ... -> leaf" paths\n        def dfs_collect_paths(node, current, res):\n            for key in node.keys():\n                res.append(current + [key])\n                dfs_collect_paths(node[key], current + [key], res)\n            return res\n        return dfs_collect_paths(tree, [], [])\n```\n\nActually it works even faster without hashing:\n```\ndef dfs(node, node_key, parent):\n  child_tuple = tuple(dfs(node[key], key, node) for key in sorted(node.keys()))\n  if child_tuple:\n    child_hashes[child_tuple].append((parent, node_key))\n  return (child_tuple, node_key)\n```\nThough I was afraid to use huge tuples during contest.
[]