FastPrepBold a Visible HTML Substring
Problems/Bold a Visible HTML Substring

Bold a Visible HTML Substring

Microsoft logoMicrosoft● MediumNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A Microsoft Applied & Data Scientist internship onsite gives an HTML article plus start and end indexes. Candidates must bold the target string. We chose these: indexes count only the visible text, the end is not included, the text sits in a single text node, input is ASCII with no entities, and the function works on raw offsets.

You are given a well-formed HTML fragment html and two indexes, start and end. The indexes count positions in the visible text, starting from zero, and end is not included. Return the two offsets [rawStart,rawEnd] in the raw HTML where <b> and </b> should be inserted, so that exactly that visible substring becomes bold.

Both offsets point into the original fragment, before either tag is inserted. Tags add no visible characters. The selected range is not empty and sits entirely inside one text node. The fragment has no entities and no existing b tags. All characters are ASCII.

Function

boldVisibleSubstring(html: String, start: int, end: int) → int[]

Examples

Example 1

html = "<p>Hello <em>world</em>!</p>"start = 6end = 11return = [13,18]

Tags add no visible characters, so the visible text is Hello world!. Indexes 6 through 10 cover world. In the raw string, world starts right after the opening em tag and ends right before the closing em tag. Those two raw offsets are the answer.

Example 2

html = "Hi <span>there</span>"start = 0end = 2return = [0,2]

The first two visible characters are Hi, and no tag comes before them. So the raw offsets are the same as the visible indexes, and the later span tag is left alone.

Constraints

  • 1 <= html.length <= 100000
  • The fragment is well formed and every tag closes with >
  • 0 <= start < end <= visibleTextLength
  • The selected visible range lies inside one text node

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

  • Invoice / Payment ReconciliationStripe · PHONE SCREEN · ONSITE INTERVIEWStripe interview questions
  • Rank Word-Translation Hints from Sentence TranslationsDuolingo · PHONE SCREEN · ONSITE INTERVIEWDuolingo interview questions
  • Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
  • Response Time Stats by URL PatternGusto · ONSITE INTERVIEWGusto interview questions
  • Most Frequent Call Path From Function Trace LogsRoblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions
  • Single-Pass S-Expression ParserBaseten · ONSITE INTERVIEWBaseten interview questions
  • Flatten a Mixed JSON ListNike, Inc. · ONSITE INTERVIEWNike, Inc. interview questions
  • Transform Dotted Keys into a Nested MapProofpoint · ONSITE INTERVIEW
  • Serialize and Deserialize a String Key-Value StoreByteDance · ONSITE INTERVIEWByteDance interview questions
  • Molecular Weight of a Grouped FormulaAgoda · ONSITE INTERVIEWAgoda interview questions

Interview reports that mention this question

  • Microsoft AI/ML Intern Interviews: 114 Experiences (Part 1 of 2)

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)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public int[] boldVisibleSubstring(String html, int start, int end) {
      // Write your code here.
    }

}
Checking account…