Rich-Text Segment Normalization and Bold Toggle
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.