Tap here to switch tabs
Problem
Submissions

Problem: Three Equal Parts

med
30 min
Try to solve the Three Equal Parts problem.

Statement

You are given an array arr containing values equal to 00 or 11. Divide the array into 33 non empty contiguous segments such that all three segments represent the same binary value.

Formally, find indices i and j with i+1<ji + 1 < j such that:

  • arr[0] through arr[i] forms the first part,

  • arr[i + 1] through arr[j - 1] forms the second part, and

  • arr[j] through arr[arr.length - 1] forms the third part.

All three parts, when evaluated as binary numbers, must represent the same value. Leading zeros are ignored when evaluating the binary value.

Return [i, j] if such a partition is possible, or [-1, -1] otherwise.

Note: A segment containing only 00 elements represents the numerical value 00.

Constraints:

  • 3≤3 \leq arr.length ≤3imes104\leq 3 imes 10^4

  • arr[i] is 00 or 11

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Three Equal Parts

med
30 min
Try to solve the Three Equal Parts problem.

Statement

You are given an array arr containing values equal to 00 or 11. Divide the array into 33 non empty contiguous segments such that all three segments represent the same binary value.

Formally, find indices i and j with i+1<ji + 1 < j such that:

  • arr[0] through arr[i] forms the first part,

  • arr[i + 1] through arr[j - 1] forms the second part, and

  • arr[j] through arr[arr.length - 1] forms the third part.

All three parts, when evaluated as binary numbers, must represent the same value. Leading zeros are ignored when evaluating the binary value.

Return [i, j] if such a partition is possible, or [-1, -1] otherwise.

Note: A segment containing only 00 elements represents the numerical value 00.

Constraints:

  • 3≤3 \leq arr.length ≤3imes104\leq 3 imes 10^4

  • arr[i] is 00 or 11