Shopify interview question
Build a file search tool with composable filters over a directory tree
- Company:
- Shopify
- Type:
- Coding
- Difficulty:
- Medium
- Reported:
- June 2, 2026
Problem
Implement a small library for searching files in a directory tree, similar to a simplified find command.
File(name, size)andDirectory(name, children)model the tree;childrenis a list of files and directories.- Filters:
NameContains(text),Extension(ext)(for example"txt", matching the part after the last dot),MinSize(n)(size at leastnbytes),MaxSize(n)(size at mostn), and the combinatorsAnd(*filters),Or(*filters)andNot(filter). find(root, flt): return the paths of all files (not directories) that matchflt, as strings joined with/starting from the root's name, sorted alphabetically.
Example 1
Input:
root = Directory("root", [File("a.txt", 120), File("b.log", 5000),
Directory("docs", [File("readme.txt", 40), File("big.txt", 9000)])])
find(root, And(Extension("txt"), MinSize(100)))
Output: ["root/a.txt", "root/docs/big.txt"]
readme.txt is too small and b.log has the wrong extension.
Example 2
Input: find(root, Or(NameContains("read"), Not(Extension("txt"))))
Output: ["root/b.log", "root/docs/readme.txt"]
b.log is not a text file and readme.txt contains "read".
Constraints
- Up to
10^5entries; directory depth up to 1000.
Reported by candidates or drawn from publicly available sources, and rewritten in our own words. Pathwise Prep does not publish confidential assessment content. Report a concern