Candy
### N children have got m pieces pf candy.They want to eat as much candy as they can, but each child must eat exacltly the same amount of candy as any other child. Determine how many pieces of candy will be eaten by all the children togerther. Individual pieces of candy cannot be split —
function candies (n , m ) {
const candy = Math.floor(m / 3)
return candy * n
}
console.log(candies(3,10))
Problem: Candies Distribution Logic
Description
This function determines the total number of candies consumed by n children when given m total candies. The core constraint is that every child must eat an equal number of full candies. Any remaining candies that cannot be split equally are left over.
Implementation Details
- Parameters:
n: Number of children.m: Total number of candies.
- Logic:
- Find the integer distribution per child using
Math.floor(m / n). - Multiply the result by the number of children to get the total consumed.
- Find the integer distribution per child using
comments powered by Disqus