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, orSTARTS WITH. The first two are obvious.STARTS WITHmeans 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.
nameSearch([ "jack", "jill", "annemarie", "anne" ], [ "jack", "", "anne", "j", "joe" ]);
[ "FOUND", "STARTS WITH", "FOUND", "STARTS WITH", "NOT FOUND" ]