Free beta: free to use with daily limits while we build. Join the waitlist for founding-member pricing at launch. Join the waitlist

Sign up free

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) and Directory(name, children) model the tree; children is 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 least n bytes), MaxSize(n) (size at most n), and the combinators And(*filters), Or(*filters) and Not(filter).
  • find(root, flt): return the paths of all files (not directories) that match flt, 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^5 entries; 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