N-ary tree filesystem with hashing
Code\n\ntype treeNode struct {\n    selfName        string\n    childrenHash    string\n    shouldDelete    bool\n    children        map[string]*treeNode\n}\n\
# Code\n```\ntype treeNode struct {\n    selfName        string\n    childrenHash    string\n    shouldDelete    bool\n    children        map[string]*treeNode\n}\n\ntype fileSystem struct {\n    root    *treeNode\n    hashD   map[string]int\n}\n\nfunc newFileSystem() *fileSystem {\n    return &fileSystem {\n        root: &treeNode {\n            selfName        : "/",\n            childrenHash    : "",\n            shouldDelete    : false,\n            children        : make(map[string]*treeNode),\n        },\n        hashD: make(map[string]int),\n    }\n}\n\nfunc (fs *fileSystem) mkdir(path []string) {\n    curr := fs.root\n    for _, pathElement := range path {\n        curr = fs.getOrCreateChild(curr, pathElement)\n    }\n}\n\nfunc (fs *fileSystem) getOrCreateChild(curr *treeNode, childName string) *treeNode {\n    v, ok := curr.children[childName]\n    if ok {\n        return v\n    }\n    // Create\n    newNode := &treeNode {\n        selfName: childName,\n        childrenHash: "",\n        shouldDelete: false,\n        children: make(map[string]*treeNode),\n    }\n    curr.children[childName] = newNode\n    return newNode\n}\n\nfunc (fs *fileSystem) getChild(curr *treeNode, childName string) *treeNode {\n    v, ok := curr.children[childName]\n    if ok {\n        return v\n    }\n    return nil\n}\n\nfunc (fs *fileSystem) getChildHash(root *treeNode) string {\n    if root == nil {\n        return ""\n    }\n    // Encoding style\n    // [kid 1{kidEncoding}, kid 2{kidEncoding}, .... , kid n{kidEncoding}]\n    // kid i\'s should be sorted in str asc.\n    kidNodeMap := make(map[string]*treeNode)\n    names := make([]string, 0)\n    for _, nodePtr := range root.children {\n        kidNodeMap[nodePtr.selfName] = nodePtr\n        names = append(names, nodePtr.selfName)\n    }\n    sort.Strings(names)\n    enc := bytes.Buffer{}\n    for i, name := range names {\n        enc.WriteString(name)\n        enc.WriteString("{")\n        enc.WriteString(fs.getChildHash(kidNodeMap[name]))\n        enc.WriteString("}")\n        if i < len(names)-1 {\n            enc.WriteString(",")\n        }\n    }\n    enc.WriteString("]")\n    encs := enc.String()\n    root.childrenHash = encs\n    fs.hashD[encs]++\n    return encs\n}\n\nfunc (fs *fileSystem) markForDeletion(root *treeNode) {\n    if root == nil {\n        return\n    }\n    cnt, ok := fs.hashD[root.childrenHash]\n    shouldDel := false\n    if ok && cnt >= 2 && len(root.children) > 0 {\n        shouldDel = true\n    }\n    root.shouldDelete = shouldDel\n    for _, node := range root.children {\n        fs.markForDeletion(node)\n    }\n} \n\nfunc (fs *fileSystem) isDeletedPath(path []string) bool {\n    curr := fs.root\n    for _, pathElement := range path {\n        curr = fs.getChild(curr, pathElement)\n        if curr == nil || curr.shouldDelete {\n            return true\n        }\n    }\n    return false\n}\n\nfunc deleteDuplicateFolder(paths [][]string) [][]string {\n    fs := newFileSystem()\n    for _, path := range paths {\n        fs.mkdir(path)\n    }\n    fs.getChildHash(fs.root)\n    fs.markForDeletion(fs.root)\n    result := make([][]string, 0)\n    for _, path := range paths {\n        if !fs.isDeletedPath(path) {\n            result = append(result, path)\n        }\n    }\n    return result\n}\n```
['Go']