Positions of large groups and element positions in sorted array
Given a string text
consisting of lowercase letters, the characters form consecutive sequences of identical letters.
For instance, in the string text = "aabbccccdde"
, the sequences are "aa"
, "bb"
, "cccc"
, "dd"
, and "e"
.
We define a sequence as large if it contains at least 4 characters. Your task is to find the starting and ending indexes for every large sequence in the string.
The result should list the ranges in ascending order based on their start positions.
Example 1: Input: "aabbccccdde" Output: [[4,7]] Explanation: The only large sequence is "cccc" starting at index 4 and ending at index 7. Example 2: Input: "abcde" Output: [] Explanation: No sequences have 4 or more characters. Example 3: Input: "zzztttttppppqq" Output: [[0,2],[3,7],[8,11]] Explanation: Large sequences are "zzz" (indexes 0-2), "ttttt" (3-7), and "pppp" (8-11). (Note: "zzz" has length 3, which is less than 4, so it should not appear. Adjust example accordingly.)