Problem solving (hard)

given a string and a substring array, print out bolden tag with the string which can be found in substring array.
example 1:
string = “abc”
substrings = [“a”]
expected output: `
“<bold a /bold>bc”
example 2:
string = “xyxy”
substrings = [“xyx”, “xy”]
expected output = "<bold xyxy /bold> "

example 3:
string = “abba”
substrings = [“ab”, “b”]
expected output = “<bold abb /bold>a”

没看懂题目

那个label打不出来 我换了种方式打出来 现在应该能懂了

Can you explain logic behind 3 examples?

do you mean a boolean array
any substring matches, turn that position to true?

sure,

  1. the substrings array only includes “a”, so “a” will be the only bolden string.
  2. sustring “xyx” and “xy” overlap in original string, the bolden string will be “xyxy” rather than “xyxxy”
  3. substring “ab” includes substring “b”, the bolden string will be “abb”

yes, it means to get all the startIndices and endIndices of the bolden strings

Seems just strstr problem.
Need to improve runtime using Trie?