Kotlin Lovers | Trie
Intuition\nStore All paths in a map. Check for repeats and mark as true. Then return the non repeat paths. \n\n\n# Approach\n Describe your approach to solving 
# Intuition\nStore All paths in a map. Check for repeats and mark as true. Then return the non repeat paths. \n\n\n# Approach\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    fun deleteDuplicateFolder(paths: List<List<String>>): List<List<String>> {\n        val trie = Trie()\n        for(p in paths){\n            trie.add(p)\n        }\n        val map = mutableMapOf<String, Boolean>()\n        trie.getSubStructure(map)\n        return trie.getNonDuplicates(map)\n    }\n}\n\n\nclass Trie(){\n    private val head = Node()\n    fun add(list: List<String>,i: Int = 0, node: Node= head){\n        if(i == list.size){\n            return\n        }\n        if(node.map[list[i]] == null){\n            node.map[list[i]] = Node()\n        }\n        add(list, i + 1, node.map[list[i]]!!)\n    }\n\n    fun getNonDuplicates(map: MutableMap<String, Boolean>, node: Node = head): List<List<String>>{\n        val op = mutableListOf<List<String>>()\n        for(k in node.map.keys){\n            if(map[node.map[k]!!.sub] != null && map[node.map[k]!!.sub]!!){continue}\n            op.add(listOf(k))\n            val tempList = getNonDuplicates(map, node.map[k]!!)\n            for(t in tempList){\n                val te = mutableListOf<String>(k)\n                te.addAll(t)\n                op.add(te.toList())\n            }\n        }\n        return op.toList()\n    }\n\n    fun getSubStructure(map: MutableMap<String, Boolean>, node: Node = head){\n        val sb = StringBuilder()\n        var space = ""\n        for(k in node.map.keys){\n            sb.append(space)\n            space = " "\n            getSubStructure(map, node.map[k]!!)\n            sb.append(k)\n            sb.append("(")\n            sb.append(node.map[k]!!.sub)\n            sb.append(")")\n        }\n        node.sub = sb.toString()\n        if(node.sub == "") return \n        if(map[node.sub]== null){\n            map[node.sub] = false\n        }else {\n            map[node.sub] = true\n        }\n        return\n    }\n}\nclass Node(){\n    var sub = ""\n    val map = TreeMap<String, Node>()\n}\n```
['Kotlin']