FastPrepApply Overlapping HTML Formatting Ranges
Problems/Apply Overlapping HTML Formatting Ranges

Apply Overlapping HTML Formatting Ranges

Benchling logoBenchling● MediumNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Benchling new grad phone screen. We follow the exercise in the report. The report leaves out some input limits and some interface details. We chose those. Our version is about 95% the same as the reported question.

Apply formatting ranges to text. Each entry in formats is type:start:end, where type is bold, italic, or underline and [start,end) is a half-open character range. Emit valid HTML using b, i, and u tags. When ranges cross, close and reopen tags as needed. Nest active tags in bold, italic, underline order.

The input is plain text, not HTML. Escape each original &, <, and > as &amp;, &lt;, and &gt;, respectively, while inserting the formatting tags. Escaping does not change the original range indices.

Function

applyHtmlFormats(text: String, formats: String[]) → String

Examples

Example 1

text = "ABCDE"formats = ["bold:0:2","italic:1:3"]return = "<b>A<i>B</i></b><i>C</i>DE"

Bold covers the first two letters and italic covers the second and third letters, so they cross at the second letter. Italic has to close before bold closes, then reopen to cover the third letter. The output closes italic, closes bold, then opens italic again for the third letter.

Constraints

  • 1 <= text.length <= 10000.
  • 0 <= formats.length <= 10000.
  • Every range satisfies 0 <= start < end <= text.length.
  • text contains ASCII characters and is plain text, not existing HTML; range indices refer to the original characters before escaping.

More Benchling interview questions

  • Bounded HTTP Retry FlowPHONE SCREEN · Seen Nov 2025
  • Future-Aware Cache EvictionPHONE SCREEN · Seen Aug 2025
  • Generate All Contiguous Protein ChainsPHONE SCREEN · Seen Jul 2024
  • Eight-Direction Keyboard Typing TimePHONE SCREEN · Seen Apr 2022
  • Generate Proteins from Contiguous Named SequencesPHONE SCREEN · Seen Aug 2021
  • Next Palindrome NumberPHONE SCREEN · Seen Jul 2021
  • Validate Nested JSON Against a SchemaONSITE INTERVIEW · Seen Dec 2025
  • Degenerate DNA Substring SearchONSITE INTERVIEW · Seen Jun 2024
  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Jul 2021
  • 2048 Move SimulatorOA · Seen Feb 2019

Similar questions at other companies

  • Time Slot Generator from Weekly Working HoursStripe · PHONE SCREENStripe interview questions
  • Cipher Cover Interval EditingDatabricks · ONSITE INTERVIEWDatabricks interview questions
  • Group Timestamps into Consecutive-Day IntervalsDuolingo · PHONE SCREENDuolingo interview questions
  • Minimum Number of Frogs CroakingCerebras · PHONE SCREEN
  • Adjacent Pair and Run RemovalWhatNot · PHONE SCREEN · ONSITE INTERVIEWWhatNot interview questions
  • In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
  • Route Pattern MatcherGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Read Across Sound TracksAirbnb · PHONE SCREENAirbnb interview questions
  • Stateful Log Transform and SearchRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
  • K-Step Bit Flip with RetentionCisco · PHONE SCREENCisco interview questions
All Benchling interview questionsSee Benchling hiring insights
Saved
class Solution {
    public String applyHtmlFormats(String text, String[] formats) {
        // Write your code here.
    }
}
Checking account…