make all values zero of an integer array with minimum no. of binary operations

Multi tool use
Multi tool use


make all values zero of an integer array with minimum no. of binary operations



I am working on a research project, where I need to convert an integer array's all value to zero using minimum no. of binary(addition/ subtraction only) operations.


For e.g.
Input Array: [ -9 , -3, -2, 8, 5, 1 ]

Output: 4

operations: op1) -9 + 8 = -1
op2) -1 + 1 = 0
op3) -3 + 5 = 2
op4) -2 + 2 = 0

Input array: [ -6, -5, -4, 6, 9]

output: 3

operations: 1) -6+6 = 0
2) -5 + 9 = 4
3) -4 + 4 =0



I cannot think of even the brute force solution.



constraints: Minimum number of Binary operations(addition/subtraction only).





Why do you need to do this?
– Tim Biegeleisen
Jul 1 at 14:30





its a variation of Hungarian algorithm with additional constraints for the project work.
– pankaj kashyap
Jul 1 at 14:35






I have updated the tags, and I know the algorithm( its a variation of Hungarian algorithm ), but due to additional constraints, I am not able to put up into the solution.
– pankaj kashyap
Jul 1 at 15:02









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

DKBqYgthrqf tPwXGMT,Y
zyoBiXpz xpJ

Popular posts from this blog

Rothschild family

Boo (programming language)