You are given a 0-indexed binary array nums of length n. nums can be divided at index i (where 0 &lt;= i &lt;= 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.

&nbsp;
Example 1:

Input: nums = [0,0,1,0]
Output: [2,4]
Explanation: Division at index
- 0: numsleft is []. numsright is [0,0,1,0]. The score is 0 + 1 = 1.
- 1: numsleft is [0]. numsright is [0,1,0]. The score is 1 + 1 = 2.
- 2: numsleft is [0,0]. numsright is [1,0]. The score is 2 + 1 = 3.
- 3: numsleft is [0,0,1]. numsright is [0]. The score is 2 + 0 = 2.
- 4: numsleft is [0,0,1,0]. numsright is []. The score is 3 + 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:

Input: nums = [0,0,0]
Output: [3]
Explanation: Division at index
- 0: numsleft is []. numsright is [0,0,0]. The score is 0 + 0 = 0.
- 1: numsleft is [0]. numsright is [0,0]. The score is 1 + 0 = 1.
- 2: numsleft is [0,0]. numsright is [0]. The score is 2 + 0 = 2.
- 3: numsleft is [0,0,0]. numsright is []. The score is 3 + 0 = 3.
Only index 3 has the highest possible division score 3.


Example 3:

Input: nums = [1,1]
Output: [0]
Explanation: Division at index
- 0: numsleft is []. numsright is [1,1]. The score is 0 + 2 = 2.
- 1: numsleft is [1]. numsright is [1]. The score is 0 + 1 = 1.
- 2: numsleft is [1,1]. numsright is []. The score is 0 + 0 = 0.
Only index 0 has the highest possible division score 2.


&nbsp;
Constraints:


	n == nums.length
	1 &lt;= n &lt;= 105
	nums[i] is either 0 or 1.


class Solution:
    def maxScoreIndices(self, nums: List[int]) -> List[int]:
        zeroFromLeft = [0] * (len(nums) + 1)
        oneFromRight = [0] * (len(nums) + 1)
        for i in range(len(nums)):
            if nums[i] == 0:
                zeroFromLeft[i + 1] = zeroFromLeft[i] + 1
            else:
                zeroFromLeft[i + 1] = zeroFromLeft[i]

        for i in range(len(nums))[::-1]:
            if nums[i] == 1:
                oneFromRight[i] = oneFromRight[i + 1] + 1
            else:
                oneFromRight[i] = oneFromRight[i + 1]

        allSum = [0] * (len(nums) + 1)
        currentMax = 0
        res = []
        for i in range(len(nums) + 1):
            allSum[i] = oneFromRight[i] + zeroFromLeft[i]
            if allSum[i] > currentMax:
                res = []
                currentMax = allSum[i]
            if allSum[i] == currentMax:
                res.append(i)
        return res
class Solution {
    public List<Integer> maxScoreIndices(int[] nums) {
        int N = nums.length;
        List<Integer> res = new ArrayList<>();

        int[] pref = new int[N + 1];
        pref[0] = 0; // at zeroth division we have no elements
        for(int i = 0; i < N; ++i) pref[i+1] = nums[i] + pref[i];

        int maxScore = -1;
        int onesToRight, zeroesToLeft, currScore;

        for(int i = 0; i < N + 1; ++i) {
            onesToRight = pref[N] - pref[i];
            zeroesToLeft = i - pref[i];
            currScore = zeroesToLeft + onesToRight;

            if(currScore > maxScore) {
                res.clear();
                maxScore = currScore;
            }
            if(currScore == maxScore) res.add(i);
        }
        return res;
    }
}
class Solution {
public:
    vector<int> maxScoreIndices(vector<int>& nums) {
        int n=nums.size();
        if(n==1)
        {
            if(nums[0]==0)
                return {1};
            else
                return {0};
        }
        int one=0,zero=0;
        for(int i=0;i<n;i++)
        {
            if(nums[i]==1)
                one++;
        }
        if(nums[0]==0)
            zero++;
        vector<int> v;
        v.push_back(one);
        int ans=one;
        if(nums[0]==1)
            one--;
        
        for(int i=1;i<n;i++)
        {
            if(nums[i]==1)
            {
                v.push_back(zero+one);
                one--;
            }
            else
            {
                v.push_back(zero+one);
                zero++;
            }
            ans=max(ans,zero+one);   
        }
        
        v.push_back(zero);
        vector<int> res;
        for(int i=0;i<=n;i++)
        {
            // cout<<v[i]<<" ";
            if(v[i]==ans)
                res.push_back(i);
        }
        return res;
    }
};
/**
 * @param {number[]} nums
 * @return {number[]}
 */
var maxScoreIndices = function(nums) {
        let n=nums.length;
        // initialize 3 arrays for counting with n+1 size
        let zeros = new Array(n+1).fill(0);
        let ones = new Array(n+1).fill(0);
        let total = new Array(n+1).fill(0);

       // count no of zeros from left to right
        for(let i=0;i<n;i++){
            if(nums[i]==0)zeros[i+1]=zeros[i]+1;
            else zeros[i+1]=zeros[i];
        }

        // count no of ones from right to left
        for(let i=n-1;i>=0;i--){
            if(nums[i]==1)ones[i]=ones[i+1]+1;
            else ones[i]=ones[i+1];
        }

        // merge left and right to total and find max element
        let max=0;
        for(let i=0;i<n+1;i++){
            total[i]=ones[i]+zeros[i];
            if(total[i]>max)max=total[i];
        }

        // Find occurrence of max elements and return those indexes
        let ans= [];
        for(let i=0;i<n+1;i++){
            if(total[i]==max)ans.push(i);
        }

        return ans;
};
All Divisions With the Highest Score of a Binary Array