Find the solution in podcast link below
Listed and read the complete Answer to this quesion
https://open.substack.com/pub/hustlercoder/p/deleting-duplicate-folders-a-pythonic-201?r=1f5fq7&utm_campaign
Listed and read the complete Answer to this quesion
https://open.substack.com/pub/hustlercoder/p/deleting-duplicate-folders-a-pythonic-201?r=1f5fq7&utm_campaign=post&utm_medium=web&showWelcomeOnShare=false

# Code
```python3 []
from typing import List, Dict

class Solution:
    def deleteDuplicateFolder(self, paths: List[List[str]]) -> List[List[str]]:
        # Step 1: Build the folder tree using a nested dictionary.
        root = {}
        for path in paths:
            curr = root
            for folder in path:
                if folder not in curr:
                    curr[folder] = {}
                curr = curr[folder]
        
        # Counter for subtree serializations and a map to store serialization for each node (by id)
        counter: Dict[str, int] = {}
        serial_map: Dict[int, str] = {}
        
        # DFS to serialize each subtree.
        def serialize(node: Dict[str, dict]) -> str:
            # Base: empty node returns empty string.
            serial = ""
            for folder in sorted(node.keys()):
                # Build serialization string for each child.
                child_serial = folder + "(" + serialize(node[folder]) + ")"
                serial += child_serial
            # Save the serialization for the current node.
            serial_map[id(node)] = serial
            counter[serial] = counter.get(serial, 0) + 1
            return serial
        
        serialize(root)
        
        # Step 2: DFS to remove duplicate subtrees.
        def remove_duplicates(node: Dict[str, dict]) -> None:
            # Iterate over a list of keys to avoid runtime error while modifying the dictionary.
            for folder in list(node.keys()):
                child = node[folder]
                # If the child's subtree is non-empty and its serialization appears more than once,
                # it is a duplicate and should be removed.
                if serial_map[id(child)] != "" and counter[serial_map[id(child)]] > 1:
                    del node[folder]
                else:
                    remove_duplicates(child)
        
        remove_duplicates(root)
        
        # Step 3: Collect the remaining folder paths.
        result = []
        def collect_paths(node: Dict[str, dict], path: List[str]) -> None:
            for folder in sorted(node.keys()):
                new_path = path + [folder]
                result.append(new_path)
                collect_paths(node[folder], new_path)
        
        collect_paths(root, [])
        return result

```
['Python3']