MEDIUMasked at 2 companies

Add Bold Tag in String

A medium-tier problem at 51% community acceptance, tagged with Array, Hash Table, String. Reported in interviews at Gusto and 1 others.

Founder's read

You're reading a string, and you need to bold specific substrings according to a dictionary. Sounds simple. It's not. TikTok and Gusto ask this one, and candidates usually get tripped up by overlapping matches, partial matches, and the order in which you apply boldface tags. The naive greedy approach fails when dictionary words can nest or conflict. This is where pattern matching and string construction collide, and half of the people who attempt it don't pass. If this problem lands in your live assessment and you blank on the ordering logic, StealthCoder surfaces a working solution in seconds, invisible to the proctor.

Companies asking
2
Difficulty
MEDIUM
Acceptance
51%

Companies that ask "Add Bold Tag in String"

If this hits your live OA

Add Bold Tag in String is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made by a working Amazon engineer who got tired of watching qualified friends bomb OAs they'd solve cold in an IDE.

Get StealthCoder
What this means

The trick: you can't just find all matches and wrap them independently. You have to iterate through the string once, checking at each position whether the dictionary contains a substring starting there, then consume that match and move forward. The catch is that multiple dictionary words might match at the same position, so you need to pick the longest one (or apply a consistent rule). A Trie structure speeds this up dramatically, avoiding repeated hash lookups. The common failure is trying to post-process the string or using regex, both of which break under overlaps. When you iterate left-to-right, greedily matching the longest dictionary word at each step, you avoid the ambiguity. If you haven't drilled the Trie construction or the greedy iteration pattern before, StealthCoder handles the algorithmic scaffolding so you don't waste fifteen minutes on the live OA figuring out the state machine.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Add Bold Tag in String recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made by a working Amazon engineer who got tired of watching qualified friends bomb OAs they'd solve cold in an IDE. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Add Bold Tag in String interview FAQ

Is this really a medium, or is the acceptance rate lying?+

The 51% acceptance rate is honest. It's medium because the concept is simple but the implementation demands careful state tracking. Most failures happen because candidates ignore overlaps or apply bold tags in the wrong order, not because the algorithm is complex.

Do I actually need a Trie, or can I get away with a hash set?+

A hash set works and is simpler to code. You iterate the string, and at each position, check all dictionary words to see which ones match starting there. It's slower but passable. A Trie is the optimization; use it only if you're comfortable building one under pressure.

What happens if dictionary words overlap in the input string?+

The greedy left-to-right approach resolves this: match and consume the longest word at each position, then continue from where it ends. This is the canonical solution TikTok and Gusto expect. No lookahead, no backtracking.

How does this relate to the String Matching and Trie topics?+

String Matching is the core: finding dictionary words inside the target string. Trie is the data structure that makes matching efficient by sharing prefixes. Together they solve the problem in O(n * m) time where n is string length and m is dictionary size, assuming Trie lookup is O(1) per character.

Why does the obvious greedy approach fail?+

It doesn't, if greedy means longest-match-first at each position. What fails is trying to find all matches globally first, then tag them. That creates conflicts and ordering nightmares. Go left to right, commit to the longest match, move past it, repeat.

Want the actual problem statement? View "Add Bold Tag in String" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.