MEDIUMasked at 2 companies

Remove Sub-Folders from the Filesystem

A medium-tier problem at 76% community acceptance, tagged with Array, String, Depth-First Search. Reported in interviews at Verkada and 1 others.

Founder's read

You're given a list of folders as strings, and you need to return only the folders that aren't subfolders of any other folder in the list. Verkada and Snowflake have both asked this one. It looks deceptively simple at first, but the trick is figuring out how to efficiently compare folder paths without brute-forcing every pair. Most candidates start with nested loops and path splitting, then hit a wall when they realize the approach is too slow or buggy for edge cases like "a/b" being inside "a/b/c". If this problem hits your live assessment and you blank on the pattern, StealthCoder solves it in seconds, invisible to the proctor.

Companies asking
2
Difficulty
MEDIUM
Acceptance
76%

Companies that ask "Remove Sub-Folders from the Filesystem"

If this hits your live OA

Remove Sub-Folders from the Filesystem is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made by a working FAANG engineer who treats the OA the way companies treat hiring: as a game with rules you should know.

Get StealthCoder
What this means

The core problem is determining parent-child relationships between folder paths. The obvious approach is to sort the folders and then, for each folder, check if it's a subfolder of any previous folder by seeing if the path starts with another path plus a slash. The trick is that simple string prefix matching breaks: "ab/cd" looks like it contains "a" if you're careless. You need the slash boundary to be explicit. Once you sort lexicographically, you only need to check if the current folder is a subfolder of the last one you kept, since any other parent would have come before it and been eliminated already. This reduces the problem from O(n^2) to O(n log n). The topics here span Array manipulation, String prefix checking, and the logical structure mirrors a Trie or DFS thinking pattern. When you're live and under pressure, StealthCoder is the hedge for the one pattern you didn't drill.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Remove Sub-Folders from the Filesystem recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made by a working FAANG engineer who treats the OA the way companies treat hiring: as a game with rules you should know. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Remove Sub-Folders from the Filesystem interview FAQ

Is this really a medium difficulty problem?+

The 75.7% acceptance rate says yes, but it's deceptive. The insight is small, but off-by-one errors on string matching and missing the sort-then-single-pass optimization trip up a lot of people. Once you see the pattern, it's a quick solve.

Why do I need to sort the folder list?+

Sorting ensures that if folder A is a parent of folder B, A comes before B. Then you only have to check each folder against the most recent one you kept, not against all previous folders. This collapses the complexity from quadratic to linear after the sort.

What's the gotcha with string prefix matching on paths?+

If you just check if one string starts with another, "ab/cd" starts with "a", but "a" is not a parent folder. You must check that the prefix is followed by a slash. The slash is the folder boundary.

Do I really need Trie or DFS for this?+

Not required, but the problem tags them because they represent valid design approaches. A Trie can build the folder hierarchy explicitly, and DFS can traverse it. The sort-and-compare approach is simpler and faster, though.

Will I see this at Verkada or Snowflake in a real OA?+

Both companies have asked it. It's a solid mid-level screening problem that tests your ability to optimize a naive solution and handle string edge cases under time pressure. It's the kind of problem you don't expect to blank on, so it stings when you do.

Want the actual problem statement? View "Remove Sub-Folders from the Filesystem" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.