Assume that Airbnb decided to enable search on user reviews. In order to make the search better, you need to tag specific words in the review. The search team has given you a bunch of tags which are key-value pairs.
The keys denote words which may or may not be present in a review, and the value corresponds to the search metadata tag.
Your task is to prepend the metadata tag and highlight the specific review word in brackets.
Input:
Review: "I visited San Francisco for work and stayed at Airbnb I really loved the city and the home where I stayed."
Tags: {"Airbnb": "business", "san francisco": "city"}
Output:
"I visited [city]{San Francisco} for work and stayed at [business]{Airbnb}. I really loved the city and the home where I stayed."
This problem asks you to annotate review text by replacing matched keywords with a tagged format like `[tag]{word}`. The main challenge is matching phrases from a key-value map against the review, often in a case-insensitive way, while preserving the original text outside the matched spans. A typical solution scans the review for all tag keys, records matching ranges, and then rebuilds the final string in order. This makes it a useful text-processing and string-matching interview problem.