Mid/SeniorArray
All Divisions With the Highest Score of a Binary Array
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:
numslefthas all the elements ofnumsbetween index0andi - 1inclusive, whilenumsrighthas all the elements ofnumsbetween indexiandn - 1inclusive.- If
i == 0,numsleftis empty, whilenumsrighthas all the elements ofnums. - If
i == n,numslefthas all the elements ofnums, whilenumsrightis empty.
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.
Return all distinct indices that have the highest possible division score. You may return the answer in any order.
Example 1
Input
nums = [0,0,1,0]Output
[2,4]Indices 2 and 4 both have the highest possible division score 3.
Example 2
Input
nums = [0,0,0]Output
[3]Only index 3 has the highest possible division score 3.
Constraints
- n == nums.length
- 1 <= n <= 10^5
- nums[i] is either 0 or 1.