-2

Problem is you are given n number of weights, we need to distribute it in both the hands so that weight difference between hand is minimum.

Eg. Weights Given : 5 8 4 Good Distribution -
Right Hand : 5 4 Left Hand : 8

Thanks in advance.

Ayush Rawat
  • 65
  • 2
  • 9

1 Answers1

1

Here is a simple strightforward algorithm to get you started.

Loop until all weights placed
    Place heaviest unplaced weight in left hand
    Loop until right hand weights > left hand weights
        Place heaviest unplaced weight less than difference in weights in hands in right hand
ravenspoint
  • 19,093
  • 6
  • 57
  • 103