Ugly unoptimised Ruby solution, still beats 100%/100%
\n# @param {String[][]} paths\n# @return {String[][]}\ndef delete_duplicate_folder(paths)\n  root = {}\n  paths.sort.each do |path|\n    cur = root\n    path.ea
```\n# @param {String[][]} paths\n# @return {String[][]}\ndef delete_duplicate_folder(paths)\n  root = {}\n  paths.sort.each do |path|\n    cur = root\n    path.each do |name|\n      cur = (cur[name] ||= {})\n    end\n  end\n    \n  @mem = Hash.new { |h, k| h[k] = [] }\n  f([], root)    \n  @mem.keep_if { |k, v| v.size > 1 && !k.empty? }\n  @mem.values.flatten(1).each do |*path, name|\n     cur = root\n     path.each do |nm|\n        cur = cur[nm]\n        break unless cur\n     end\n     next unless cur\n     cur.delete(name)\n  end\n  g([], root)\nend\n\n\ndef g(path, node)\n  node.flat_map do |name, subnode|\n    pp = path + [name]\n    [pp] + g(pp, subnode)\n  end\nend\n\ndef f(path, node)\n  @mem[node] << path\n  node.each { |name, subnode| f(path + [name], subnode) }\nend\n```
[]