2155. All Divisions With the Highest Score of a Binary Array Medium
1/**
2 * [2155] All Divisions With the Highest Score of a Binary Array
3 *
4 * You are given a 0-indexed binary array nums of length n. nums can be divided at index i (where 0 <= i <= n) into two arrays (possibly empty) numsleft and numsright:
5 *
6 * numsleft has all the elements of nums between index 0 and i - 1 (inclusive), while numsright has all the elements of nums between index i and n - 1 (inclusive).
7 * If i == 0, numsleft is empty, while numsright has all the elements of nums.
8 * If i == n, numsleft has all the elements of nums, while numsright is empty.
9 *
10 * The division score of an index i is the sum of the number of 0's in numsleft and the number of 1's in numsright.
11 * Return all distinct indices that have the highest possible division score. You may return the answer in any order.
12 *
13 * Example 1:
14 *
15 * Input: nums = [0,0,1,0]
16 * Output: [2,4]
17 * Explanation: Division at index
18 * - 0: numsleft is []. numsright is [0,0,<u>1</u>,0]. The score is 0 + 1 = 1.
19 * - 1: numsleft is [<u>0</u>]. numsright is [0,<u>1</u>,0]. The score is 1 + 1 = 2.
20 * - 2: numsleft is [<u>0</u>,<u>0</u>]. numsright is [<u>1</u>,0]. The score is 2 + 1 = 3.
21 * - 3: numsleft is [<u>0</u>,<u>0</u>,1]. numsright is [0]. The score is 2 + 0 = 2.
22 * - 4: numsleft is [<u>0</u>,<u>0</u>,1,<u>0</u>]. numsright is []. The score is 3 + 0 = 3.
23 * Indices 2 and 4 both have the highest possible division score 3.
24 * Note the answer [4,2] would also be accepted.
25 * Example 2:
26 *
27 * Input: nums = [0,0,0]
28 * Output: [3]
29 * Explanation: Division at index
30 * - 0: numsleft is []. numsright is [0,0,0]. The score is 0 + 0 = 0.
31 * - 1: numsleft is [<u>0</u>]. numsright is [0,0]. The score is 1 + 0 = 1.
32 * - 2: numsleft is [<u>0</u>,<u>0</u>]. numsright is [0]. The score is 2 + 0 = 2.
33 * - 3: numsleft is [<u>0</u>,<u>0</u>,<u>0</u>]. numsright is []. The score is 3 + 0 = 3.
34 * Only index 3 has the highest possible division score 3.
35 *
36 * Example 3:
37 *
38 * Input: nums = [1,1]
39 * Output: [0]
40 * Explanation: Division at index
41 * - 0: numsleft is []. numsright is [<u>1</u>,<u>1</u>]. The score is 0 + 2 = 2.
42 * - 1: numsleft is [1]. numsright is [<u>1</u>]. The score is 0 + 1 = 1.
43 * - 2: numsleft is [1,1]. numsright is []. The score is 0 + 0 = 0.
44 * Only index 0 has the highest possible division score 2.
45 *
46 *
47 * Constraints:
48 *
49 * n == nums.length
50 * 1 <= n <= 10^5
51 * nums[i] is either 0 or 1.
52 *
53 */
54pub struct Solution {}
55
56// problem: https://leetcode.com/problems/all-divisions-with-the-highest-score-of-a-binary-array/
57// discuss: https://leetcode.com/problems/all-divisions-with-the-highest-score-of-a-binary-array/discuss/?currentPage=1&orderBy=most_votes&query=
58
59// submission codes start here
60
61impl Solution {
62 pub fn max_score_indices(nums: Vec<i32>) -> Vec<i32> {
63 vec![]
64 }
65}
66
67// submission codes end
68
69#[cfg(test)]
70mod tests {
71 use super::*;
72
73 #[test]
74 fn test_2155() {
75 }
76}
77
Back
© 2025 bowen.ge All Rights Reserved.