Delete duplicate files via DFS
Company: Applied Intuition
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Overview: This question evaluates a candidate's skills in file-system traversal using DFS/backtracking, duplicate detection across hierarchical directories, and algorithmic techniques such as hashing and efficient data-structure use.
Constraints
- 1 <= total number of directories + files <= 20000
- All 'name' fields are non-empty and do not contain '/'
- File 'content' is a string; two files are duplicates if their 'content' strings are equal
- Directory depth can be large; use iterative DFS to avoid recursion-depth issues
- Return the deletion list sorted lexicographically
- Absolute path format: '/' + root name + '/' + ... + '/' + file name
Hints
- Traverse the directory tree with DFS using an explicit stack to build absolute paths.
- Use a hash map from content to the smallest (lexicographic) path seen so far.
- Collect all (content, path) pairs, then delete all paths that are not the minimal path for their content.
- Sort the resulting deletion list for deterministic output.