Techno Blender
Digitally Yours.
Browsing Tag

consisting

Min cost required to make the Array sum zero consisting of 1 and -1

Given an array arr of size N containing only +1 and -1, the task is to make the sum of the array zero with the given operation. In a single operation, any element can be updated as arr = arr * (-1). Each operation cost 10 units. the task is to print the minimum cost required to make the sum of the array zero. If the sum cannot be made zero, then print -1.Examples:Input: N = 6, arr = {1, 1, -1, -1, 1, 1}Output: 10Explanation: The sum of the array is 2, if we perform the given operation one time at any index with value +1,…