[Kotlin] Simple kotlin solution with explanation
Approach\n1. First, build a tree from the lists. \n2. Then, do a dfs pass through to build the serialized content of each dir (there\'s some trickiness here as 
# Approach\n1. First, build a tree from the lists. \n2. Then, do a dfs pass through to build the serialized content of each dir (there\'s some trickiness here as if you\'re not careful a serialization is not neccessarily unique.). While building this serialization, use a hashmap to keep track of how often we\'ve seen each content.\n3. Go through the tree a second time with dfs. Ignore all nodes where the content serialization occurs more than once in the map we\'ve built in the previous step.\n\n# Complexity\n- Time complexity:\n$$O(n) = n *k$$ (k = length of path)\nWe basically do one pass through the list ($$O(n*k)$$) to build the tree, then dfs twice to filter and build the result ($$O(n)$$).\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 root = Node("")\n        buildTree(root, paths)\n\n        val contentOccurences = mutableMapOf<String, Int>()\n        buildContent(root, contentOccurences)\n        System.out.println(contentOccurences.entries.joinToString())\n\n        val output = mutableListOf<List<String>>()\n        buildOutput(root, emptyList(), contentOccurences, output)\n        return output\n    }\n\n    private fun buildTree(root: Node, paths: List<List<String>>) {\n      paths.forEach { path ->\n        var curr = root\n        path.forEach { filename ->\n          curr = curr.children.find { it.name == filename } ?: \n          Node(filename).also{ curr.children.add(it) }\n        }\n      }\n    }\n\n    private fun buildContent(root: Node, occurenceMap: MutableMap<String, Int>): String {\n      val sep = ";"\n      val dirSep = "/"\n      if (root.children.isEmpty()) {\n        return root.name + dirSep\n      }\n      val content = root.children\n                        .sortedBy { it.name } \n                        .map { buildContent(it, occurenceMap) }\n                        .joinToString(sep)\n      occurenceMap[content] = (occurenceMap[content] ?: 0) + 1\n      root.content = content\n      return "${root.name}$dirSep${root.children.size}$content"\n    }\n\n    private fun buildOutput(root: Node,\n     currList: List<String>,\n     occurenceMap: Map<String, Int>,\n     output: MutableList<List<String>>) {\n      val isRootOfDir = root.name.isEmpty()\n      val appendedList = if (isRootOfDir) currList else currList.plus(root.name)\n      if (!isRootOfDir) {\n        output.add(appendedList)\n      }\n\n      root.children\n          .filter { it.content.isEmpty() || occurenceMap[it.content] == 1}\n          .forEach {\n            buildOutput(it, appendedList, occurenceMap, output)\n          }\n    }\n}\n\ndata class Node(val name: String, var content: String = "", val children: MutableList<Node> = mutableListOf())\n```
['Kotlin']