2663. Distribute Money to Maximum Children
My accepted JavaScript solution to LeetCode problem 2663, Distribute Money to Maximum Children, running in 3ms.
- Difficulty: Easy
- JavaScript
- Runtime 3ms
- Memory 60.5MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
JavaScript
Accepted on LeetCode — runtime 3ms, memory 60.5MB, accepted 2025-12-29.
/**
* @param {number} money
* @param {number} children
* @return {number}
*/
var distMoney = function(money, children) {
if (money < children) return -1;
money -= children;
let eights = Math.min(Math.floor(money / 7), children);
money -= eights * 7;
if (eights === children && money > 0) return eights - 1;
if (eights === children - 1 && money === 3) return eights - 1;
return eights;
}