All Divisions With the Highest Score of a Binary Array LeetCode solution in Java
1class Solution {2public List<Integer> maxScoreIndices(int[] nums) {3int N = nums.length;4List<Integer> res = new ArrayList<>();56int[] pref = new int[N + 1];7pref[0] = 0; // at zeroth division we have no elements8for (int i = 0; i < N; ++i) pref[i + 1] = nums[i] + pref[i];910int maxScore = -1;11int onesToRight, zeroesToLeft, currScore;1213for (int i = 0; i < N + 1; ++i) {14onesToRight = pref[N] - pref[i];15zeroesToLeft = i - pref[i];16currScore = zeroesToLeft + onesToRight;1718if (currScore > maxScore) {19res.clear();20maxScore = currScore;21}22if (currScore == maxScore) res.add(i);23}24return res;25}26}