Skip to content

Practice Three Equal Parts

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#927
LeetCode Problem

Three Equal Parts

Problem Statement

Split binary array arr into three nonempty contiguous parts with equal binary values. Return any [i, j] defining arr[0..i], arr[i+1..j-1] and arr[j..n-1], so i + 1 < j. Interpret every bit of each part; leading zeros are allowed, while trailing zeros affect the value. Return [-1, -1] when no valid split exists.

Source: Three Equal Parts on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
arr = [1,0,1,0,1]
Output
[0,3]

# Example 2

Input
arr = [1,1,0,1,1]
Output
[-1,-1]

# Example 3

Input
arr = [1,1,0,0,1]
Output
[0,2]

Constraints

3 <= arr.length <= 3 * 10^4
arr[i] is 0 or 1

Related LeetCode Problems

Practice more problems similar to Three Equal Parts.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.