In a string s&nbsp;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&nbsp;"yy".

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

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

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

&nbsp;
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".


&nbsp;
Constraints:


	1 &lt;= s.length &lt;= 1000
	s contains lowercase English letters only.


class Solution:
    def largeGroupPositions(self, s: str) -> List[List[int]]:

        i=0
        c=1
        prev=""
        l=len(s)
        ans=[]
        while i<l:
            if s[i]==prev:
                c+=1
                if (i==l-1) & (c>=3):
                    ans.append([i+1-c,i])
            else:
                if c>=3:
                    ans.append([i-c,i-1])
                c=1
            prev=s[i]
            i+=1
        return ans
class Solution {
    public List<List<Integer>> largeGroupPositions(String s) {
        List<List<Integer>> res = new ArrayList<>();
        List<Integer> tmp = new ArrayList<>();
        int count = 1;
        
        for (int i = 0; i < s.length() - 1; i++) {
            // Increment the count until the next element is the same as the previous element. Ex: "aaa"
            if (s.charAt(i) == s.charAt(i + 1)) {
                count++;
            } 
            // Add the first and last indices of the substring to the list when the next element is different from the previous element. Ex: "aaab"
            else if (s.charAt(i) != s.charAt(i + 1) && count >= 3) {
                // gives the starting index of substring
                tmp.add(i - count + 1);
                // gives the last index of substring 
                tmp.add(i);
                res.add(tmp);
                count = 1;
                tmp = new ArrayList<>();
            } 
            else {
                count = 1;
            }
        }

        // Check for a large group at the end of the string. Ex: "abbb".
        if (count >= 3) {
            tmp.add(s.length() - count);
            tmp.add(s.length() - 1);
            res.add(tmp);
        }

        return res;
    }
}
class Solution {
public:
    vector<vector<int>> largeGroupPositions(string s) {
        vector<vector<int>> res;
        
        int st = 0;
        int en = 1;
        
        while(en < s.size())
        {
            if(s[en] != s[st])
            {
                if(en-st >= 3)
                {
                    res.push_back({st, en-1});
                    
                }
                st = en;
                en = st+1;
            }
            else
            {
                en++;
            }
        }
        
        if(en-st >= 3)
        {
            res.push_back({st, en-1});
        }
        
        return res;
    }
};
// 77 ms, faster than 97.56%
// 45 MB, less than 87.81%
var largeGroupPositions = function(s) {
	let re = /(.)\1{2,}/g;
	let ans = [];
	while ((rslt = re.exec(s)) !== null) {
		ans.push([rslt.index, rslt.index + rslt[0].length-1]);
	}
	return ans;
};
Positions of Large Groups