Ali OA Interview Problem: Summarize Selected Directories

18 Views
No Comments

Given a list of current directories and a list of selected directories, return the selected directories after summarizing.

Example:

The entire directories:

/a/b/x.txt
/a/b/p.txt
/a/c
/a/d/y.txt
/a/d/z.txt

The selected directories:

/a/d/y.txt
/a/d/z.txt
/a/b/p.txt

This problem asks you to summarize a list of selected directory paths against the full set of available paths. A common approach is to normalize the paths, then use prefix checks, sorting, a hash set, or a trie to merge items that can be represented at a higher directory level while preserving the meaning of the selection. The key is to detect redundant nested paths and return a clean summarized list.

END
 0