Positions of Large Groups - Problem

In a string s of lowercase letters, these letters form consecutive groups of the same character.

For example, a string like s = "abbxxxxzyy" has the groups "a", "bb", "xxxx", "z", and "yy".

A group is identified by an interval [start, end], where start and end denote the start and end indices (inclusive) of the group. In the above example, "xxxx" has the interval [3,6].

A group is considered large if it has 3 or more characters.

Return the intervals of every large group sorted in increasing order by start index.

Input & Output

Example 1 — Basic Case
$ Input: s = "abbxxxxzyy"
Output: [[3,6]]
💡 Note: The groups are "a" (length 1), "bb" (length 2), "xxxx" (length 4), "z" (length 1), "yy" (length 2). Only "xxxx" has length ≥ 3, spanning indices [3,6].
Example 2 — Multiple Large Groups
$ Input: s = "abcdddeeeeaabbbcd"
Output: [[3,5],[6,9],[12,14]]
💡 Note: Groups: "a"(1), "b"(1), "c"(1), "ddd"(3), "eeee"(4), "aa"(2), "bbb"(3), "c"(1), "d"(1). Large groups are "ddd" [3,5], "eeee" [6,9], "bbb" [12,14].
Example 3 — No Large Groups
$ Input: s = "abc"
Output: []
💡 Note: All groups have length 1, which is less than 3, so no large groups exist.

Constraints

  • 1 ≤ s.length ≤ 1000
  • s consists of lowercase English letters only

Visualization

Tap to expand
Positions of Large Groups: "abbxxxxzyy"Inputabbxxxxzyy0123456789Groups"a" len=1"bb" len=2"xxxx" len=4 ≥ 3 ✓"z" len=1"yy" len=2Output[[3,6]]Only group "xxxx" has length ≥ 3
Understanding the Visualization
1
Input String
String with consecutive character groups
2
Find Groups
Identify consecutive same characters and their lengths
3
Filter Large
Return intervals of groups with length ≥ 3
Key Takeaway
🎯 Key Insight: Track group boundaries by detecting character changes in a single pass
Asked in
Google 12 Facebook 8
15.4K Views
Medium Frequency
~15 min Avg. Time
485 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen