jmdons's blog

By jmdons, history, 4 years ago, In English

Can someone please help me understand the below solution.

Problem statement --> Array Division

Solution on GitHub --> Solution Here

After mulling over it and trying to find out what the code does leaves me with the following understanding.

A binary search is used to find the desired maxnumber which obviously lies between max(array) and sum of all elements of the array.

somehow only for the desired maxnumber the number of sets (counter) calculated with the condition equals the input k:

if (currentsum + currentelement > maxnumber)
    counter++;
    currentsum = 0;

Can someone please explain to me the relation between the maxnumber and number of sets (k), which is exploited in this solution ? It would be of immense help. Thanks in advance!

Full text and comments »

  • Vote: I like it
  • +2
  • Vote: I do not like it