Javascript/Typescript Trie Simple Solution (100% faster than the rest)
Based on solution by @GeorgeChryso, added sorting while creating hash to work with scenario when sub folders are arranged in unsorted manner. (like a folder x c
Based on solution by @GeorgeChryso, added sorting while creating hash to work with scenario when sub folders are arranged in unsorted manner. (like a folder x can have c,d subfolders, and when we create hash for marking these items for deletion, if other folder has d,c folder name, it would not work)\n\n```\nclass PathTrieNode {\n  val = \'\';\n  children = new Map<string, PathTrieNode>();\n  hash = \'\';\n  // Parent pointer is important when we are trying to delete nodes.\n  parent: PathTrieNode | undefined;\n}\n\nclass PathTrie {\n  private root = new PathTrieNode();\n  private hashMemMap = new Map<string, PathTrieNode[]>();\n  \n  /**\n  * Builds Trie tree for each path passed in Test Case\n  */\n  build(path: string[]): void {\n      let node = this.root;\n      for (let pathVal of path) {\n          if (!node.children.has(pathVal)) {\n              const childNode = new PathTrieNode();\n              childNode.parent = node;\n              childNode.val = pathVal;\n              node.children.set(childNode.val, childNode);\n              node = childNode;\n          } else {\n              node = node.children.get(pathVal);\n          }\n      }\n  }\n\n  /**\n  * Creates hash for a node based on it\'s sub folders\n  *  Note that sorting for subfolder is important.\n  */\n  createHash(node = this.root): string {\n      if (node.children.size === 0) {\n          // leaf node\n          return node.val;\n      }\n      let hash = [];\n      for (let child of node.children.values()) {\n          hash.push(this.createHash(child));\n      }\n      hash = hash.sort();\n      node.hash = hash.join(\'~\');\n      if (!this.hashMemMap.has(node.hash)) {\n          this.hashMemMap.set(node.hash, [])\n      }\n      this.hashMemMap.get(node.hash).push(node);\n      return node.val + \'[\' + node.hash + \']\';\n  }\n  \n  /**\n  * Deletes similar folders as map would contain more than one entries for those.\n  * For deleting a node, we go its parent, and delete parent\'s connection to child.\n  */\n  removeDuplicates(node = this.root): void {\n      if (this.hashMemMap.has(node.hash) && this.hashMemMap.get(node.hash).length > 1) {\n          for (let deleteNode of this.hashMemMap.get(node.hash)) {\n              deleteNode.parent.children.delete(deleteNode.val);\n          }\n      }\n      for (let child of node.children.values()) {\n          this.removeDuplicates(child);\n      }\n  }\n  \n  /**\n  * Stack is used to track folder structure (dfs kind of thing)\n  * Res contains actual items.\n  */\n  toArray(node = this.root, stack = [], res = []): string[][] {\n      if (node.val !== \'\') {\n          stack.push(node.val);\n          res.push([...stack]);\n      }\n      for (let child of node.children.values()) {\n          this.toArray(child, stack, res);\n      }\n      stack.pop();\n      return res;\n  }\n  \n}\n\nfunction deleteDuplicateFolder(paths: string[][]): string[][] {\n  const pathTrie = new PathTrie();\n  for (let path of paths) {\n      pathTrie.build(path);\n  }\n  pathTrie.createHash();\n  pathTrie.removeDuplicates();\n  return pathTrie.toArray();\n};\n\n```
['TypeScript', 'JavaScript']