You are provided with a list of business names called bizNames. Write a function that searches these names and returns the top k that contain a specific prefix. The prefix can appear at the beginning of any word within a business name, and the search should be case-insensitive.
Results are ordered using two criteria:
prefix is a non-empty string. Matching is case-insensitive.k is a positive integer.Example 1:
bizNames = ["Bobs Burgers", "Burger King", "McDonald's", "Five Guys", "Super Duper Burgers", "Wahlburgers"], prefix = "Bur", k = 2
["Burger King", "Bobs Burgers"]
Splitting "Burger King" gives ["Burger", "King"]. The prefix "Bur" matches "Burger" at index 0. Splitting "Bobs Burgers" gives ["Bobs", "Burgers"]. The prefix "Bur" first matches "Burgers" at index 1. No other name has a match. Ordered by their occurrence index, the top 2 are ["Burger King", "Bobs Burgers"].
Example 2:
bizNames = ["Apple Store", "Google", "Microsoft"], prefix = "Z", k = 2
[]
Example 3:
bizNames = ["Alpha Beta", "Alpha Gamma", "Beta Alpha", "AlphaGo"], prefix = "alpha", k = 2
["Alpha Beta", "Alpha Gamma"]
Explanation:
- For "Alpha Beta", the prefix "alpha" matches the first word "alpha" at index 0.
- "Alpha Gamma" also finds a match at index 0 with "alpha". "Beta Alpha" finds its first match at index 1 with "alpha", and "AlphaGo" matches at index 0. The index-0 matches are "Alpha Beta", "Alpha Gamma", and "AlphaGo". The top 2 by alphabetical order among these are "Alpha Beta" and "Alpha Gamma".