Yelp | Phone | Implement a prefix based search.

This post is in continuation of Online Assessment Test post (https://leetcode.com/discuss/interview-question/838686/yelp-oa-2020-filter-the-businesses-and-return-ordered-list/696180).

Interview Round 1

Problem :
Given a list of business_names (strings) and a searchTerm (string).
Return a list of business_names that contains searchTerm as prefix in the business_names.

E.g.
Example 1.
Input:

business_names[] = { "burger king", "McDonald's", "super duper burger's", "subway", "pizza hut"}
searchTerm = "bur"

Ouput:
["burger king", "super duper burger's"]

Example 2
Input:

business_names[] = { "burger king", "McDonald's", "super duper burger's", "subway", "pizza hut"}
searchTerm = "duper bur"

Ouput:
["super duper burger's"]

Expected to discuss the approach and implement the solution.
(Allowed to run and debug the code as many times as we want, in order to make it error free)

Comments (21)