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:

  • 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.

Example 1
Inputnums = [0,0,1,0]
Output[2,4]
Indices 2 and 4 both have the highest possible division score 3.
Example 2
Inputnums = [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.

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate