C++ | O(N) | Commented Code | easy to understand
\nclass Solution {\npublic:\n    vector<int> threeEqualParts(vector<int>& arr) {\n        \n        int ones = 0;\n        int n  = arr.size();\n        \n     
```\nclass Solution {\npublic:\n    vector<int> threeEqualParts(vector<int>& arr) {\n        \n        int ones = 0;\n        int n  = arr.size();\n        \n        for(int i : arr){\n            if(i==1)\n                ones++;\n        }\n        \n        //if no ones\n        if(ones == 0) return {0,n-1};\n        //if irregular ones, that cannot be divided in 3 parts\n        if(ones%3!=0) return {-1,-1};\n        \n        int k = ones/3;\n        \n        //we find the starting position of 3 parts since leading zeroes does not matter\n        int firstOne = -1, secondOne = -1, thirdOne = -1;\n        int cnt1 = 0, cnt2 = 0, cnt3 = 0;\n        \n        //Find first one\n        for(int i=0;i<n;i++){\n            if(arr[i]==1){\n                firstOne = i;\n                break;\n            }\n        }\n        //Find second one\n        for(int i=firstOne+1;i<n;i++){\n            if(arr[i]==1) cnt2++;\n            if(arr[i]==1 && cnt2==k){\n                secondOne = i;\n                break;\n            }\n        }\n        //Find third one\n        for(int i=secondOne+1;i<n;i++){\n            if(arr[i]==1) cnt3++;\n            if(arr[i]==1 && cnt3==k){\n                thirdOne = i;\n                break;\n            }\n        }\n        \n        //checking if they are equal\n        int x = firstOne, y = secondOne, z = thirdOne;\n        while(x<n && y<n && z<n){\n            if(arr[x] == arr[y] && arr[y] == arr[z]){\n                x++;y++;z++;\n            }\n            else\n                return {-1,-1};\n        }\n        \n        //after the while loop we\'ll have the\n        //    |      |\n        //  1 | 0 1  | 0 1\n        //    |      |\n        //      ^      ^    ^\n        //      |      |    |\n        //      x      y    z\n\n        return {x-1,y};\n        \n    }\n};\n```
['C']