Filter hierarchical paths after deletions
SnowflakeSoftware Engineer · Technical ScreenLast updated
This question evaluates proficiency in hierarchical string processing, prefix-based filtering, edge-case handling (duplicates, trailing slashes, empty inputs), data-structure selection, and algorithmic time/space complexity analysis within the Coding & Algorithms domain, emphasizing practical implementation over purely conceptual reasoning.
Given two arrays: (
- paths — slash-delimited hierarchical strings such as "California", "California/San Francisco", "California/San Francisco/7th Street"; and (
- deletes — paths to remove such as "California/San Francisco". Remove every path that is equal to or a descendant of any path in deletes, and return the remaining paths (order your choice). Design an efficient solution (e.g., Trie or sorting plus prefix-skipping), handle edge cases (duplicates, overlapping deletes, trailing slashes, empty arrays), and analyze time and space complexity. Implement the core function.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.