Review Token Tagging

Asked at AirbnbPhone screen

Reported by the problem's creator, not verified

A review site marks the names it knows. You get a review text and a map tokens that maps each token to a label. Write tag_review(review, tokens), which returns the review with every occurrence of a token wrapped as [label]{text}, where text is the occurrence exactly as it appears in the review.

Matching ignores case, so the token san francisco matches San Francisco, and the wrapped text keeps the casing of the review. A token may contain spaces and punctuation, and it matches only that exact sequence of characters (a single space matches a single space). A token matches anywhere, including inside a longer word. Everything outside matches is copied unchanged.

Examples

  1. Example 1

    Input: {"review":"I booked a house on Airbnb for my trip to San Francisco. It was a lovely experience.","tokens":{"Airbnb":"business","san francisco":"city"}}

    Output: I booked a house on [business]{Airbnb} for my trip to [city]{San Francisco}. It was a lovely experience.

    Explanation: Airbnb matches itself, and san francisco matches San Francisco across the space. Each match keeps the casing the review used, so the label wraps San Francisco, not san francisco.

Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.
Import a question

Code

Loading editor…

Ln 1, Col 1

Start an attempt to use Coach.