Bold Words in String
CodingOnsiteMachine Learning EngineerReported Apr, 2026
Examples
Example 1:
Input: words = ["ab","bc"]
s = "aabcd"
Output: "a<b>abc</b>d"
Explanation:
Example 2:
Input: words = ["ab","cb"]
s = "aabcd"
Output: "a<b>ab</b>cd"
Example 1:
Input: words = ["ab","bc"]
s = "aabcd"
Output: "a<b>abc</b>d"
Explanation:
Example 2:
Input: words = ["ab","cb"]
s = "aabcd"
Output: "a<b>ab</b>cd"
Given an array of keywords words and a string s, make all appearances of all keywords words[i] in s bold. Any letters between <b> and </b> tags become bold.
Return s after adding the bold tags. The returned string should use the least number of tags possible, and the tags should form a valid combination.
"ab" appears at index 1, "bc" appears at index 2. Their marked ranges overlap into one bold region covering indices 1..3.
1 <= s.length <= 5000 <= words.length <= 501 <= words[i].length <= 10s and words[i] consist of lowercase English letters.