Due to a bug, there are many duplicate folders in a file system. You are given a 2D array paths, where paths[i] is an array representing an absolute path to the i-th folder in the file system.
For example, ["one", "two", "three"] represents the path /one/two/three.
Two folders (not necessarily at the same level) are identical if they contain the same non-empty set of identical subfolders and underlying subfolder structure. Two folders are considered identical if their serialized subtree structures are the same.
If two or more folders are identical, then mark the folders as well as all their subfolders. Once all duplicate folders have been marked, the file system will delete all of them. The file system only runs the deletion once, so any folders that become identical after the deletion are not deleted.
Return the 2D array ans containing the paths of the remaining folders after deleting all the marked folders. The paths may be returned in any order.
Example 1:
Input: paths = [["a"],["c"],["d"],["a","b"],["c","b"],["d","a"]]
Output: [["d"],["d","a"]]
Explanation: Folders /a and /c both have a subfolder b, making them identical. They are deleted. Folder /d has subfolder a (not b), so it remains.
Example 2:
Input: paths = [["a"],["c"],["a","b"],["c","b"],["a","b","x"],["a","b","x","y"],["w"],["w","y"]]
Output: [["c"],["c","b"],["a"],["a","b"]]
Explanation: Folders /a/b/x and /w are identical (both have subfolder y). They are deleted. Their parents /a/b and /a remain because they are no longer identical to /c/b and /c after the deletion.
Example 3:
Input: paths = [["a","b"],["c","d"],["c"],["a"]]
Output: [["c"],["c","d"],["a"],["a","b"]]
Explanation: Folders /a/b and /c/d are leaf folders with no subfolders so their subtrees are empty and not considered identical. All folders remain.
1 <= paths.length <= 2 * 10^41 <= paths[i].length <= 5001 <= paths[i][j].length <= 101 <= sum(paths[i][j].length) <= 2 * 10^5paths[i][j] consists of lowercase English letters