427. Distribute Candies Among Children III
You are provided with two positive integers n and limit.
Return the total number of distinct ways to distribute exactly n candies among 3 children such that no child receives more than limit candies.
Example 1:
Input : n = 5, limit = 2
Output : 3
Explanation : There are 3 valid distributions: (1, 2, 2), (2, 1, 2), and (2, 2, 1), with each child receiving at most 2 candies.
Example 2:
Input : n = 3, limit = 1
Output : 1
Explanation : Only one distribution works here: (1, 1, 1), where every child gets exactly 1 candy.
Now Your Turn!
Pick the correct output for the given inputInput : n = 7, limit = 3
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 1 <= n <= 10⁸
- 1 <= limit <= 10⁸