Rich-Text Segment Normalization and Bold Toggle
Updated
Problem statement
Each string in segments has format BI:text. B and I are 0 or 1 for the bold and italic flags; text is nonempty lowercase text.
- Normalize the input by merging adjacent segments with identical bold and italic flags.
- Using character positions in the concatenated text, toggle the bold flag for the half-open range
[start,end). Preserve text order and italic flags, split segments at range boundaries, and normalize adjacent equal-style segments again.
Return the normalized encoded segments.
Function
toggleBoldRange(segments: String[], start: int, end: int) → String[]Examples
Example 1
segments = ["10:ab","10:cd","00:ef"]start = 1end = 5return = ["10:a","00:bcd","10:e","00:f"]The first two segments merge to abcd. Toggling indices 1 through 4 unbolds bcd and bolds e; a and f keep their styles.
Example 2
segments = ["00:abc","01:def"]start = 0end = 6return = ["10:abc","11:def"]The entire text becomes bold while each italic flag is preserved.
Example 3
segments = ["10:a","10:b"]start = 1end = 1return = ["10:ab"]The empty range changes nothing, and normalization merges the two segments.
Constraints
1 <= segments.length <= 100000.- Total text length is at most
300000. - Every segment matches
[01][01]:[a-z]+. 0 <= start <= end <= total text length.
More Scale AI Onsite Interview questions
- Task Scheduler with DependenciesONSITE INTERVIEW · Seen Jul 2026
- Best Poker Category with a JokerPHONE SCREEN · ONSITE INTERVIEW · Seen Jun 2026
- Format and Validate a Model ResponseONSITE INTERVIEW · Seen Apr 2026
- Stateful Neuron Matrix UpdateONSITE INTERVIEW · Seen Apr 2026
- Clock Hand Angle with Subsecond PrecisionONSITE INTERVIEW · Seen Dec 2025
- Four-Player Matching Card GameONSITE INTERVIEW · Seen Feb 2025
- Rotate an Array to the RightONSITE INTERVIEW · Seen Oct 2024
- Minimum Distance Matching in a ForestPHONE SCREEN · ONSITE INTERVIEW · Seen Feb 2024
- Shortest Distance Between Two NodesONSITE INTERVIEW · Seen Jan 2024
- Fit Beta Parameters by Maximum LikelihoodONSITE INTERVIEW · Seen Sep 2022
Similar questions at other companies
- Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
- Digit-Coded Card ValidationCapital One · ONSITE INTERVIEWCapital One interview questions
- Compress Editor Actions into Operational Transform OperationsReplit · OA · PHONE SCREEN · ONSITE INTERVIEW
- Path Leaf Character IteratorGoogle · ONSITE INTERVIEWGoogle interview questions
- Trace Events from Stable Whole-Stack StatesAnthropic · ONSITE INTERVIEWAnthropic interview questions
- Hex Dump FormatterWaymo · ONSITE INTERVIEWWaymo interview questions
- Cipher Cover Interval EditingDatabricks · ONSITE INTERVIEWDatabricks interview questions
- Most Frequent Call Path in Interleaved LogsRoblox · ONSITE INTERVIEWRoblox interview questions
- Parse Command-Line TokensSamsara · ONSITE INTERVIEWSamsara interview questions
- Deterministic Word Guess SolverAtlassian · ONSITE INTERVIEWAtlassian interview questions
Scale AI interview experiences
- Scale AI OA: What It Tests (2026)
- Scale AI Forward Deployed Engineer Debugging Round: 1 Experience
- Scale AI ML Research Engineering Intern Interviews: 1 Experience
- Scale AI SWE Intern Debugging Interview: 9 Experiences
- Scale AI New Grad SWE and MLE Question Bank
- Scale AI New Grad SWE Poker Screen and Onsite: 1 Experience