Leetcode Problem 2928. Distribute Candies Among Children I
2928. Distribute Candies Among Children I
Leetcode Solutions
Simple loops Only
Initialize a counter to keep track of the number of valid distributions.
Use a loop to iterate through all possible candy amounts for the first child, from 0 to the minimum of n and limit.
Inside the first loop, use another loop to iterate through all possible candy amounts for the second child, from 0 to the minimum of n - i (remaining candies after giving to the first child) and limit.
Calculate the third child's share as n - i - j, where i is the first child's share and j is the second child's share.
If the third child's share is within the limit, increment the counter.
Return the counter as the total number of valid distributions.