DEV Community

Minh Hieu
Minh Hieu

Posted on

Chocolate Feast Explain - Solution | Javascript

function chocolateFeast(n, c, m) {
  let candy = Math.floor(n / c);
  let wrapper = candy;
  let result = candy;
  while(wrapper >= m) {
    const exchanged = Math.floor(wrapper / m);
    wrapper = wrapper - (exchanged * m) + exchanged;
    result+= exchanged;
  }
  return result;
}

chocolateFeast(10, 2, 5);

Problem

Top comments (0)