Twenty-ish LOCs 🤩
"Clean code should read like well-written prose" \u2013 Robert C. Martin\n\nc#\npublic class Solution {\n    public IList<IList<string>> DeleteDuplicateFolder(I
_"Clean code should read like well-written prose" \u2013 Robert C. Martin_\n\n```c#\npublic class Solution {\n    public IList<IList<string>> DeleteDuplicateFolder(IList<IList<string>> paths) {\n        var root = new TrieNode();\n        var path2node = paths.ToDictionary(p => p, p => root.NodeByPath(p));\n        var uniqueNodes = root.Flatten().GroupBy(n => n.Hash).Where(g => g.Count() == 1).SelectMany(g => g).ToHashSet();\n        return paths.Where(p => uniqueNodes.Contains(path2node[p].ClosestNotLeaf)).ToList();\n    }\n    \n    class TrieNode {\n        private string hash;\n        private TrieNode parent;\n        private Dictionary<string, TrieNode> children = new Dictionary<string, TrieNode>();\n        public TrieNode ClosestNotLeaf => children.Any() ? this : parent;\n        public string Hash => hash ?? (hash = string.Concat(from c in children orderby c.Key select (c.Key, c.Value.Hash)));\n        public IEnumerable<TrieNode> Flatten() => children.Values.SelectMany(n => n.Flatten()).Prepend(this);\n        public TrieNode NodeByPath(IList<string> path, int i = 0) {\n            if (i == path.Count) return this;\n            children.TryAdd(path[i], new TrieNode { parent = this });\n            return children[path[i]].NodeByPath(path, i + 1);\n        }\n    }\n}\n```
[]