Java Solution with Explanation
First build a tree of folders as shown in the problem description\n\nNext generate a key for each node in the tree\nThe key should be a concatenation of the key
First build a tree of folders as shown in the problem description\n\nNext generate a key for each node in the tree\nThe key should be a concatenation of the keys of all it\'s children. It is important to sort all it\'s children before concatenating the key. If the insertion order is a/x , a/y , b/y, b/x. This would ensure that the key generated for both a and b is key(x) + key(y) in that order;\nWhile genrating the key we also add the keys to a global map\n\nAfter that perform another transveral and set the delete flag of nodes that are not leafs and their keys are duplicate\n\nFinally for each path initially given, if it\'s possible to go to the end of the path without passing a node whose deleted flag has been set, add it to the result\n\nPlease upvote if you like the solution :) \n```\n\nclass Solution {\n    Folder root = new Folder("");\n    Map<String, Integer> keys = new HashMap<>();\n    \n    public List<List<String>> deleteDuplicateFolder(List<List<String>> paths) {\n        for (List<String> path : paths){\n            addPath(path);\n        }\n        \n        for (Folder f : root.list){\n            generateKey(f);\n        }\n        \n        for (Folder f : root.list){\n            updateDeleteStatus(f);\n        }\n        \n        List<List<String>> results = new ArrayList<>();\n        \n        for (List<String> path : paths){\n            if (isValid(path))\n                results.add(path);\n        }\n        \n        return results;\n    }\n    \n    private boolean isValid(List<String> path){\n        Folder current = root;\n        \n        for (String f : path){\n            current = current.map.get(f);\n            \n            if (current.del)\n                return false;\n        }\n        \n        return true;\n    }\n    \n    private void updateDeleteStatus(Folder f){\n        if (f.list.size() > 0 && keys.get(f.key) > 1){\n            f.del = true;\n            return;\n        }\n        \n        for (Folder fold : f.list){\n            updateDeleteStatus(fold);\n        }\n    }\n    \n    private String generateKey(Folder fold){\n        StringBuilder sb = new StringBuilder();\n        \n        if (fold.list.size() == 0)\n            return sb.toString();\n        \n        // sort to order matches\n        Collections.sort(fold.list, (a, b) -> a.name.compareTo(b.name));\n        \n        for (Folder f : fold.list){\n            sb.append(\'(\');\n            sb.append(f.name + generateKey(f));\n            sb.append(\')\');\n        }\n        \n        String key = sb.toString();\n        fold.key = key;\n        keys.put(key, keys.getOrDefault(key, 0) + 1);\n        \n        return key;\n    }\n    \n    private void addPath(List<String> path){\n        Folder current = root;\n        \n        for (String f : path){\n            if (!current.map.containsKey(f)){\n                Folder fold = new Folder(f);\n                current.map.put(f, fold);\n                current.list.add(fold);\n            }\n            \n            current = current.map.get(f);\n        }\n    }\n}\nclass Folder{\n    String name;\n    Map<String, Folder> map;\n    List<Folder> list;\n    String key;\n    boolean del;\n    \n    Folder(String name){\n        this.name = name;\n        map = new HashMap<>();\n        list = new ArrayList<>();\n        key = "";\n        del = false;\n    }\n}\n```
[]