LC: 1231. Divide Chocolate - spiralgo/algorithms GitHub Wiki

1231. Divide Chocolate:

The Essence: A trial-and-error method empowered by Binary Search would be a good mechanism to try a sweetness value.

  • If the number of the splits required for the current sweetness value is greater than allowed (k cuts) we should decrease the split number, therefore we can increase the sweetness value.

  • If the number of the splits required for the current sweetness value is smaller than allowed (k cuts) we should increase the split number, therefore we must decrease the sweetness value.

Details:

You can find a clean but elegant Binary Search implementation and explanation here: https://github.com/spiralgo/algorithms/pull/369