Three Pointers || C++ || O(N) time || O(1) space
Approach: First of all, it is necessary for the given array to have sufficient count of ones which can be equally divided among three groups. If not, the answer
**Approach:** First of all, it is necessary for the given array to have sufficient count of ones which can be equally divided among three groups. If not, the answer is not possible. If yes, find the occurances of the first ones of each group. Now, simply iterate over these pointers and check whether you can atleast reach to the starting index of other group. If so, return the indexes else answer is not possible. \n**Time complexity:** O(N)\n**Space complexity:** O(1)\n```\nclass Solution {\npublic:\n    vector<int> check(vector<int> s, int i, int j, int k) {\n        int n=s.size();\n        while(i<j && j<k && k<n) {\n            if(s[i]!=s[j] || s[j]!=s[k]) return {-1,-1};\n            if(i==j || j==k || k==n) break;\n            i++;\n            j++;\n            k++;\n        }\n        if(i==j || j==k || k==n) return {i-1, j};\n        return {-1,-1};\n    }\n    vector<int> threeEqualParts(vector<int>& arr) {\n        int n=arr.size();\n        int ctr=count(arr.begin(), arr.end(),1);\n        if(ctr % 3 != 0) return {-1,-1};\n        \n        vector<int> ans(3,-1);\n        int k=0, ref=0;\n        for(int i=0;i<n;i++) { \n            if(arr[i] && !ref) {\n                ans[k++]=i;\n            }\n            if(arr[i]) ref++;\n            \n            if(ref==ctr/3) {\n                ref=0;\n            }\n        }\n        if(ans[0]==ans[1] && ans[1]==ans[2]) return {0, n-1};\n        return check(arr, ans[0], ans[1], ans[2]);\n    }\n};\n```\n**Upvote if u liked!!**
['C']