927. Three Equal Parts Hard
1/**
2 * [927] Three Equal Parts
3 *
4 * You are given an array arr which consists of only zeros and ones, divide the array into three non-empty parts such that all of these parts represent the same binary value.
5 * If it is possible, return any [i, j] with i + 1 < j, such that:
6 *
7 * arr[0], arr[1], ..., arr[i] is the first part,
8 * arr[i + 1], arr[i + 2], ..., arr[j - 1] is the second part, and
9 * arr[j], arr[j + 1], ..., arr[arr.length - 1] is the third part.
10 * All three parts have equal binary values.
11 *
12 * If it is not possible, return [-1, -1].
13 * Note that the entire part is used when considering what binary value it represents. For example, [1,1,0] represents 6 in decimal, not 3. Also, leading zeros are allowed, so [0,1,1] and [1,1] represent the same value.
14 *
15 * Example 1:
16 * Input: arr = [1,0,1,0,1]
17 * Output: [0,3]
18 * Example 2:
19 * Input: arr = [1,1,0,1,1]
20 * Output: [-1,-1]
21 * Example 3:
22 * Input: arr = [1,1,0,0,1]
23 * Output: [0,2]
24 *
25 * Constraints:
26 *
27 * 3 <= arr.length <= 3 * 10^4
28 * arr[i] is 0 or 1
29 *
30 */
31pub struct Solution {}
32
33// problem: https://leetcode.com/problems/three-equal-parts/
34// discuss: https://leetcode.com/problems/three-equal-parts/discuss/?currentPage=1&orderBy=most_votes&query=
35
36// submission codes start here
37
38impl Solution {
39 pub fn three_equal_parts(arr: Vec<i32>) -> Vec<i32> {
40 vec![]
41 }
42}
43
44// submission codes end
45
46#[cfg(test)]
47mod tests {
48 use super::*;
49
50 #[test]
51 fn test_927() {
52 }
53}
54
Back
© 2025 bowen.ge All Rights Reserved.