#927

Three Equal Parts

master · 1680 · lc hard +32 · verified · 41.3% accepted · 855 likes · top 22%

Description

Given a binary array arr of 0s and 1s, find a way to split it into three non-empty contiguous parts that each represent the same binary integer. Return [i, j] where the three parts are arr[0..i], arr[i+1..j-1], and arr[j..n-1], or [-1, -1] if no such partition exists.

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]

Code

1
2
3