Trains the technique from
LeetCode 616Add Bold Tag in StringThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A line of text line and a list of terms are given. Wherever a term turns up inside line, that stretch of the line has to be wrapped between the markers <hi> and </hi>.
Stretches may overlap or sit flush against each other. Use as few pairs of markers as possible, so any stretches that overlap or touch end up inside a single pair.
Return the marked-up line.
Example 1
One term sits at the fourth letter and the other starts the second word. The two stretches neither touch nor overlap, so each takes its own pair of markers.
Example 2
The two stretches share the letter d, so they go inside a single pair of markers rather than two.
Example 3
With no terms to look for the line comes back untouched.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def add_bold_tag(line: str, terms: list[str]) -> str:public String addBoldTag(String line, String[] terms)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.