#830
Positions of Large Groups
pupil · 430 · lc easy +25 · verified · 53.8% accepted · 927 likes · top 45%
Description
In a string s of lowercase letters, consecutive runs of the same character form groups.
For example, s = "abbxxxxzyy" contains the groups "a", "bb", "xxxx", "z", and "yy".
Each group is represented by the interval [start, end] of its indices (inclusive). The group "xxxx" above spans [3, 6].
A group is large if its length is at least 3.
Return the intervals of all large groups, sorted by starting index.
Example 1:
Input: s = "abbxxxxzzy"
Output: [[3,6]]
Explanation: "xxxx" is the only large group with start index 3 and end index 6.
Example 2:
Input: s = "abc"
Output: []
Explanation: We have groups "a", "b", and "c", none of which are large groups.
Example 3:
Input: s = "abcdddeeeeaabbbcd"
Output: [[3,5],[6,9],[12,14]]
Explanation: The large groups are "ddd", "eeee", and "bbb".
Code
1
2
3