Italicize Matching Word Regions
Updated
Problem statement
Given a larger string text and a list of non-empty words, surround every character belonging to a literal word occurrence with italic XML tags <i> and </i>. Matches are case-sensitive and may overlap.
Merge overlapping or immediately adjacent matching ranges into one region, so the returned string contains no redundant inner tag pairs. Preserve all original characters and their order. Words may repeat, and either the text or the word list may be empty.
Function
italicizeWordMatches(text: String, words: String[]) → StringExamples
Example 1
text = "abcxyz123"words = ["abc","123"]return = "<i>abc</i>xyz<i>123</i>"Two disjoint matching regions remain separate.
Example 2
text = "aaabbcc"words = ["aaa","aab","bc"]return = "<i>aaabbc</i>c"Overlapping matches extend one connected region.
Example 3
text = "abcdef"words = ["ab","cd","ef"]return = "<i>abcdef</i>"Adjacent matching regions combine without inner tag pairs.
Constraints
0 <= text.length <= 2000and0 <= words.length <= 100.- Every word contains between
1and50characters. - Text and words contain ASCII letters, digits and spaces; they contain no XML-special characters.
More Microsoft Onsite Interview questions
- Bad Request AlertsONSITE INTERVIEW · Seen Nov 2026
- Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
- Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
- Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
- Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
- Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
- Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
- Coin ChangeONSITE INTERVIEW · Seen Oct 2026
- Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
- Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Travelers per Consecutive City TripletUber · ONSITE INTERVIEWUber interview questions
- Rank Word-Translation Hints from Sentence TranslationsDuolingo · PHONE SCREEN · ONSITE INTERVIEWDuolingo interview questions
- Group AnagramsAmazon Web Services · ONSITE INTERVIEWAmazon Web Services interview questions
- Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
- Response Time Stats by URL PatternGusto · ONSITE INTERVIEWGusto interview questions
- Shortest Uncommon SubstringAirbnb · ONSITE INTERVIEWAirbnb interview questions
- Longest Consecutive Login StreakAmazon · ONSITE INTERVIEW
- Digit-Coded Card ValidationCapital One · ONSITE INTERVIEWCapital One interview questions
- Keyboard Autocomplete SuggestionsLyft · ONSITE INTERVIEWLyft interview questions
- Compress Editor Actions into Operational Transform OperationsReplit · OA · PHONE SCREEN · ONSITE INTERVIEW
Microsoft interview experiences
- Microsoft OA Questions, October 2026: 4 Experiences
- Microsoft Experienced SWE Phone Screen: 1 Experience
- Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
- Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
- Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
- Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)