Drop Nested Folders Already Covered by a Shared Parent Folder
Last updated: November 29, 2026
Quick Overview
Given a list of absolute folder paths shared to a Workplace group, remove every folder that is inside another folder in the list and return the remaining top-level folders.
Meta
November 29, 20260
0
0 solved
Given a list of absolute folder paths shared to a Workplace group, remove every folder that is inside another folder in the list and return the remaining top-level folders.
Sharing a folder implicitly shares its subfolders, so the backend can collapse redundant entries. This checks string prefix reasoning and the classic trap that /a/b is not a parent of /a/bc.
What the Interviewer Expects
- Sort paths so parents come before children
- Compare against the last kept path with a trailing slash
- Avoid the /a/b versus /a/bc false match
- Offer a trie over path segments as an alternative
- State complexity in total characters
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you handle paths with trailing slashes or '..'?
- How would you do this incrementally as shares are added?
- What if you needed to remove parents instead of children?
- How would you handle case-insensitive file systems?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Paths are distinct, start with
/, contain lowercase letters, and have no trailing slash. - A folder is redundant if some other path is a strict ancestor.
- Return the remaining paths in any order....
High-Level Design
Sort the paths lexicographically. A parent /a always sorts before its children /a/b..., and anything between them in sorted order also starts with /a, so it suffices to compare each path with th...