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:
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).
If i == 0, numsleft is empty, while numsright has all the elements of nums.
If i == n, numsleft has all the elements of nums, while numsright is 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.
Input: nums =[0,0,1,0]Output: [2,4]Explanation: Division at index
-0: numsleft is[]. numsright is[0,0,_**1**_ ,0]. The score is0+1=1.-1: numsleft is[_**0**_]. numsright is[0,_**1**_ ,0]. The score is1+1=2.-2: numsleft is[_**0**_ ,_**0**_]. numsright is[_**1**_ ,0]. The score is2+1=3.-3: numsleft is[_**0**_ ,_**0**_ ,1]. numsright is[0]. The score is2+0=2.-4: numsleft is[_**0**_ ,_**0**_ ,1,_**0**_]. numsright is[]. The score is3+0=3.Indices 2 and 4 both have the highest possible division score 3.Note the answer [4,2] would also be accepted.
Example 2:
1
2
3
4
5
6
7
8
Input: nums =[0,0,0]Output: [3]Explanation: Division at index
-0: numsleft is[]. numsright is[0,0,0]. The score is0+0=0.-1: numsleft is[_**0**_]. numsright is[0,0]. The score is1+0=1.-2: numsleft is[_**0**_ ,_**0**_]. numsright is[0]. The score is2+0=2.-3: numsleft is[_**0**_ ,_**0**_ ,_**0**_]. numsright is[]. The score is3+0=3.Only index 3 has the highest possible division score 3.
Example 3:
1
2
3
4
5
6
7
Input: nums =[1,1]Output: [0]Explanation: Division at index
-0: numsleft is[]. numsright is[_**1**_ ,_**1**_]. The score is0+2=2.-1: numsleft is[1]. numsright is[_**1**_]. The score is0+1=1.-2: numsleft is[1,1]. numsright is[]. The score is0+0=0.Only index 0 has the highest possible division score 2.
The key idea is to efficiently compute, for every possible division index, the number of zeros to the left and the number of ones to the right. By precomputing prefix sums of zeros and total ones, we can calculate the division score for each index in constant time.