Typescript, documented to be easy-to-understand
\nfunction threeEqualParts(dd: number[]) {\n  // Every part has to have the same number of digit 1, and so it must be divisible by 3.\n  const countOnes = dd.re
```\nfunction threeEqualParts(dd: number[]) {\n  // Every part has to have the same number of digit 1, and so it must be divisible by 3.\n  const countOnes = dd.reduce<number>((total, i) => total + (i === 1 ? 1 : 0), 0);\n  if (countOnes === 0) return [0, 2];\n  if (countOnes % 3 !== 0) return [-1, -1];\n\n  // Get inclusive indexes of the middle part, from 1 to 1. So in "1010 101 0101"\n  // the indexes would be 4 to 6. Same number of 1s in each third.\n  let [i, j] = (() => {\n    let indexes = [];\n    let ones = 0;\n    for (let inx = 0; inx < dd.length && indexes.length < 2; inx++) {\n      if (dd[inx] === 1) {\n        ones++;\n        if (ones === (countOnes * 2) / 3) indexes.push(inx);\n        if (ones === countOnes / 3 + 1) indexes.push(inx);\n      }\n    }\n    return [indexes[0], indexes[1]];\n  })();\n\n  // Every number has to have the same number of zeros on the end as the last number.\n  // Otherwise their values won\'t be the same.\n  const requiredZerosAtEnd = dd.length - dd.lastIndexOf(1, dd.length - 1) - 1;\n\n  // Try to adjust the middle number by incrementing j so it has proper number of 0s on\n  // the end.\n  const zerosRight = (inx: number) => {\n    const nextOne = dd.indexOf(1, inx + 1);\n    return nextOne === -1 ? dd.length - inx - 1 : nextOne - inx - 1;\n  };\n  if (zerosRight(j) >= requiredZerosAtEnd) {\n    j += requiredZerosAtEnd;\n  } else {\n    return [-1, -1];\n  }\n\n  // Try to adjust the first number by moving i so it has proper number of 0s on the end.\n  const lastOneInFirstPart = dd.lastIndexOf(1, i - 1);\n  if (zerosRight(lastOneInFirstPart) >= requiredZerosAtEnd) {\n    i = lastOneInFirstPart + requiredZerosAtEnd + 1;\n  } else {\n    return [-1, -1];\n  }\n\n  // Compare the three numbers, bit by bit, to see if they are the same.\n  [i, j] = [i - 1, j + 1];\n  let aStart = dd.indexOf(1, 0);\n  let bStart = dd.indexOf(1, i + 1);\n  let cStart = dd.indexOf(1, j);\n  while (cStart !== dd.length) {\n    if (dd[aStart] === dd[bStart] && dd[bStart] === dd[cStart]) {\n      aStart++;\n      bStart++;\n      cStart++;\n    } else return [-1, -1];\n  }\n  return [i, j];\n}\n```
[]