As reported: Microsoft L60 SDE (Aug 2025), round 2 (DSA, 60 minutes; two questions planned, production-quality code and test cases expected): LeetCode Add Bold Tag in String, solved by merging overlapping intervals; the interviewer gave no hints.
You are given a string s and an array of strings words. Wrap every substring of s that matches a word in words with <b> and </b>:
- If two such substrings overlap, wrap them together with one pair of tags.
- If two bolded substrings are consecutive (one ends right where the next starts), combine them too.
Return s after adding the tags.
This is LeetCode 616 — Add Bold Tag in String.
Example 1
s = "abcxyz123", words = ["abc","123"] -> "<b>abc</b>xyz<b>123</b>"
Example 2
s = "aaabbb", words = ["aa","b"] -> "<b>aaabbb</b>"
"aa" matches at 0 and 1, and "b" at 3, 4 and 5; [0,1] and [1,2] overlap, and [0,2] touches [3,5], so everything is one bold part.
Constraints: 1 ≤ s.length ≤ 1000; 0 ≤ words.length ≤ 100; 1 ≤ words[i].length ≤ 1000; s and words[i] consist of English letters and digits; all words are unique.
Code runner format: one JSON value per line: s, then words (LeetCode's test-case format). Implement addBoldTag(s, words); the harness prints the result.