Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    2928 - Distribute Candies Among Children I\.

    Easy

    You are given two positive integers n and limit.

    Return the total number of ways to distribute n candies among 3 children such that no child gets more than limit candies.

    Example 1:

    Input: n = 5, limit = 2

    Output: 3

    Explanation: There are 3 ways to distribute 5 candies such that no child gets more than 2 candies: (1, 2, 2), (2, 1, 2) and (2, 2, 1).

    Example 2:

    Input: n = 3, limit = 3

    Output: 10

    Explanation: There are 10 ways to distribute 3 candies such that no child gets more than 3 candies: (0, 0, 3), (0, 1, 2), (0, 2, 1), (0, 3, 0), (1, 0, 2), (1, 1, 1), (1, 2, 0), (2, 0, 1), (2, 1, 0) and (3, 0, 0).

    Constraints:

    • 1 <= n <= 50

    • 1 <= limit <= 50

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      Solution()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Integer distributeCandies(Integer n, Integer limit)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait