Leetcode 857 Solution

This article provides solution to leetcode question 857 (positions-of-large-groups)

https://leetcode.com/problems/positions-of-large-groups

Solution

class Solution {
public:
    vector<vector<int>> largeGroupPositions(string S) {
        vector<vector<int>> ans;

        int l = 0;
        for (int r = 0; r <= S.size(); r++)
        {
            if (S[l] != S[r])
            {
                if (r - l >= 3)
                    ans.push_back({l, r - 1});
                l = r;
            }
        }

        return ans;
    }
};