Facebook | Phone | add <b> tag around the matching word of any sentence
Anonymous User
906

Last week I had my facebook phone interview for Ph.D. intern(ML). The interviewer asked me the following question.

You are given a dictionary of word and a sentence. Find all the word in a sentence and add <b></b> tag around that sentence. If the tag overlaps combine them. Also if there are two if there are two adjacent <b></b> tag then combine them.

s = "abacaxcy"
d = {"aba", "ac", "y", "c"}
output = "<b>abac</b>ax<b>cy</b>"
Comments (1)