25. Directory Search

Difficulty: 

We have a large directory of first names, and would like to search for quite a few names in it. The outcome of every search is one the following: NOT FOUND, FOUND, or STARTS WITH. The first two are obvious. STARTS WITH means that there is at least one name on the directory that starts with the searched name.

For example, if the directory is ["jack", "jill", "annemarie"], the answers to the queries of ["joe", "jill", "anne"] will be ["NOT FOUND", "FOUND", "STARTS WITH"].

Try solving the problem without searching the whole directory for every query. All the names consist of lower-case letters only.

Input:

nameSearch([
  "jack",
  "jill",
  "annemarie",
  "anne"
], [
  "jack",
  "",
  "anne",
  "j",
  "joe"
]);

Output:

[
  "FOUND",
  "STARTS WITH",
  "FOUND",
  "STARTS WITH",
  "NOT FOUND"
]

Time Limit:

50 (ms)

Hint (hover to see):

  • Hint #1



Results

ProblemsAcceptedWrongTimed OutError
40000

Input:

Expected Output:

Output: