Airbnb OA 面试真题解析:Tag and Highlight Review Words

12次阅读
没有评论

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."

这道题的核心是对评论文本做“关键词标注”和“高亮替换”。给定一组关键词到标签的映射,需要在原文中找到对应词组,并将其替换成 `[tag]{word}` 的形式。实现时通常要注意大小写不敏感匹配、短语可能由多个单词组成,以及多个匹配之间的顺序和边界处理。常见做法是先遍历标签字典,定位所有命中的区间,再按原文顺序重建字符串,避免重复替换或漏标。

正文完
 0