c++(24ms 99,40%) pointers , three pass (greedy)
Runtime: 24 ms, faster than 99.40% of C++ online submissions for Three Equal Parts.\nMemory Usage: 38.9 MB, less than 55.42% of C++ online submissions for Three
Runtime: 24 ms, faster than 99.40% of C++ online submissions for Three Equal Parts.\nMemory Usage: 38.9 MB, less than 55.42% of C++ online submissions for Three Equal Parts.\n**General idea:**\n**1.** If we can split this array for three equal parts we MUST have total number of "ones" is uqual 3* k \n**2.** split our array for three parts with equal numbers of "ones" \n**3.** value of zerous between first and second parts and between second and thrid parts not can be less than value of contigious zerous in end of array. check it.\n**4.** tree parts will be the same\n![image](https://assets.leetcode.com/users/images/88c4f6f0-cb70-4219-aa3e-774739e32386_1626519129.532363.png)\n\n![image](https://assets.leetcode.com/users/images/26500242-fe5a-41f7-b907-e06d7054fa8e_1626520214.916899.png)\n\n\n\n\n```\nclass Solution {\npublic:\n  vector<int> threeEqualParts(vector<int>& arr) {\n    int ones = 0, N = arr.size();\n    for(auto &x: arr) if(x) ones++;\n    if(ones%3 != 0) return{-1,-1};                //check ones\n    if(ones == 0) return {0,2};\n    ones /= 3;\n    \n    int zeroes = 0, i = N - 1;                       //last contigious zerous\n    while(arr[i--] == 0) zeroes++;\n ///////////////////////////////////////////(splitting)   \n    int si = -1, sj, j, id = 0, n;\n    \n    while(arr[id] == 0) si++, id++;           //"si"\n    \n    n = ones;\n    while(n) if(arr[id++] == 1) n--;          // "i" without zerous\n    i = id-1;\n    \n    int nz = 0;\n    while(arr[id] == 0) nz++, id++;\n    if(nz < zeroes) return {-1,-1};\n    i += zeroes, sj = id;                     // "i" and "sj" \n    \n    n = ones;\n    while(n) if(arr[id++] == 1) n--;          // "j"   without zerous\n    j = id;\n    \n    nz = 0;\n    while(arr[id] == 0) nz++, id++;\n    if(nz < zeroes) return {-1,-1};           // "j" and id\n    j += zeroes;\n    \n  /////////////////////////////////////////////////// second part(if we can split)  \n    if(i - si != N - id || i - si != j - sj ) return {-1,-1};              //if three word havent the same length\n    \n    int limit = j - sj - zeroes;                              //old version ->         int limit = j - sj;   \n    for(int a = si + 1, b = sj, c = id; limit; a++, b++, c++, limit--)\n      if(arr[a] != arr[b] || arr[a] != arr[c]) return {-1,-1};\n    \n    return {i,j};\n  }\n};\n```
['C', 'C++']