Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Change the zeros in nums to -1 and create a prefix sum array prefixSum using the new nums.
If prefixSum[i] for any index i in the range 0 <= i < prefixSum.length is positive, that means that there are more ones than zeros in the prefix ending at index i.
If prefixSum[j] > prefixSum[i] for two indexes i and j such that 0 <= i < j < prefixSum.length, that means that there are more ones than zeros in nums in the range [i + 1 : j] (inclusive)