intervals to store the intervals where keywords appear.words, find all occurrences in s and add the corresponding intervals to intervals.intervals based on the start index of each interval.merged to store the merged intervals.intervals and merge overlapping or consecutive intervals.result and a variable last to keep track of the end of the last merged interval.merged and construct result by appending non-bold parts of s and the bold parts with tags.s after the last interval to result.result.