FastPrepSearch a File Collection

Search a File Collection

Google logoGoogle● EasyNEW GRADPHONE SCREEN
Learn

Problem statement

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.

More Google problems

See Google hiring insights
public String[] searchFiles(String[] operations) {
    // Write your code here.
}
operations["ADD /docs/report.txt","ADD /tmp/notes.txt","FIND .txt","FIND port"]
expected["/docs/report.txt|/tmp/notes.txt", "/docs/report.txt"]
Checking account…