Search a File Collection
Reported by candidates from Google's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The Google OA reported in September 2026 looks like a file search box, and the detail that matters is that duplicates get ignored and results come back sorted. You process ADD and FIND operations on a collection of unique, case-sensitive paths. FIND matches against the final filename only, not the whole path. Output is pipe-joined matches or NONE. It's a hinted binary-search problem, but the real work is keeping a sorted structure and scanning it right. If you blank on the day, StealthCoder is the safety net running invisibly in the assessment.
The problem
Process an ordered batch of operations on an initially empty collection of unique, case-sensitive file paths. ADD path stores the path. Adding an existing path changes nothing. FIND fragment finds every stored path whose final filename contains fragment. Return matching paths in lexicographic order, joined by |, or NONE when no path matches. Return one result string for each FIND operation; ADD operations do not add output entries. Function searchFiles(operations: String[]) → String[] Examples Example 1 operations = ["ADD /docs/report.txt","ADD /tmp/notes.txt","FIND.txt","FIND port"] return = ["/docs/report.txt|/tmp/notes.txt","/docs/report.txt"] Both text files match the first query; only report.txt contains port. Example 2 operations = ["ADD /a/photo.png","ADD /b/photo.png","ADD /a/photo.png","FIND photo","FIND.jpg"] return = ["/a/photo.png|/b/photo.png","NONE"] Duplicate insertion is ignored, and the second query has no matches. Constraints 1 <= operations.length <= 10^4 Paths and fragments are nonempty printable strings without spaces or |. Every path contains at least one filename character after its final slash.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is to keep stored paths in a sorted list and use binary search to insert. A set handles the duplicate check, and bisect keeps lexicographic order without re-sorting on every FIND. For FIND, extract the substring after the last slash from each path and test whether it contains the fragment. Then join the matches with | in sorted order. With at most 10^4 operations, a linear scan per FIND is fine. Don't overbuild a trie or suffix structure. The common pitfalls are matching against the whole path instead of the filename, so FIND docs wrongly hits /docs/x.txt. Others are forgetting NONE, and emitting output for ADD. Also remember matching is case-sensitive, so don't lowercase anything. If the parsing or the sorted insert slips under pressure, StealthCoder can give you a working solution live in the OA.
If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.
You can drill Search a File Collection cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Google's OA.
Google reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Search a File Collection FAQ
How hard is the Google Search a File Collection question really?+
It's easy to medium. No deep algorithm is needed. The difficulty is careful parsing and edge cases: filename-only matching, duplicate ADDs, case sensitivity, and NONE output. If you read the spec slowly, it's very doable.
What's the trick to this problem?+
Keep unique paths in a sorted structure, using a set plus a sorted list or bisect insertion. On FIND, take the substring after the last slash and check whether it contains the fragment. Matches come out already in lexicographic order, so you just join them.
Do I need a trie or suffix structure?+
No. With up to 10^4 operations, scanning stored paths per FIND is fast enough. A trie adds bug risk and doesn't help with substring matching on filenames. Simple and correct beats clever here.
What edge cases break most solutions?+
Matching the fragment against the full path instead of the filename is the big one. Others are adding duplicates twice, lowercasing strings when matching is case-sensitive, returning an empty string instead of NONE, and appending output for ADD operations.
How do I prepare in 48 hours?+
Practice string parsing with split on the first space, bisect insertion in your language, and substring checks. Write the solution once from scratch, then test both examples plus a no-match and a duplicate case. That covers nearly everything this problem tests.