All Divisions With the Highest Score of a Binary Array
specialist · 630 · lc medium +30 · verified · 65.5% accepted · 538 likes · top 70%
Description
You are given a 0-indexed binary array nums of length n. The array can be split at any index i (where 0 <= i <= n) into a left part and a right part (either may be empty):
- The left part contains all elements at indices 0 through i - 1.
- The right part contains all elements at indices i through n - 1.
- When i == 0, the left part is empty and the right part is all of nums.
- When i == n, the left part is all of nums and the right part is empty.
The division score at index i equals the number of 0s in the left part plus the number of 1s in the right part.
Return all indices that achieve the highest division score. The answer may be in any order.
Example 1:
Example 2:
Example 3:
Code