You are given a binary array A of size n. The frequency of 1s in the array is never greater than ⌊N/2⌋ and the remaining positions are filled with 0s.
The task is to convert all 1s to -1. We can convert 1 to -1 by pairing an existing 0 from the array with the 1. After this operation, the existing 1 and 0 both become -1. The cost of pairing two elements at index i and j is abs(i-j).
Minimize the cost of converting all 1s to -1.
Note: We have to convert all 1s to -1, not necessarily all the 0s. So, if at any point, all 1s have been converted to -1 but there are still 0s in the array, the task is considered completed.
Constraints: 2 <= N <= 4000