Algorithm · Yelp · Medium
Problem You are given a string of words separated by spaces and a dictionary of valid bigrams. A bigram is a pair of consecutive words that should be treated as a single token. Your job is to segment the input string according to these rules: Preserve the original order of the words. Whenever two adjacent words form a bigram that exists in the dictionary, merge them into one token. If multiple bigram matches could overlap, always choose the leftmost valid match and skip over…
Checking your access…