Skip to content

1948. Delete Duplicate Folders in System #1948

Answered by mah-shamim
mah-shamim asked this question in Q&A
Discussion options

You must be logged in to vote

We need to identify and delete duplicate folders in a file system. Two folders are considered identical if they contain the same non-empty set of identical subfolders and the same underlying subfolder structure. The solution involves building a trie to represent the folder structure, using a post-order DFS to compute a unique hash for each folder's subtree, marking duplicate folders, and then collecting the remaining folders after deletion.

Approach

  1. Build the Trie: Construct a trie (prefix tree) where each node represents a folder. The root node is virtual and does not correspond to any folder in the paths. Each path from the root to a node represents an absolute path in the file system.
  2. C…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@kovatz
Comment options

kovatz Jul 20, 2025
Collaborator

@mah-shamim
Comment options

mah-shamim Jul 20, 2025
Maintainer Author

Answer selected by kovatz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested hard Difficulty
2 participants