LeetCode solutions

3199. Distribute Candies Among Children I

My accepted Python solution to LeetCode problem 3199, Distribute Candies Among Children I, running in 13ms.

  • Difficulty: Easy
  • Python
  • Runtime 13ms
  • Memory 17.5MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 13ms, memory 17.5MB, accepted 2026-01-02.

python
class Solution:
    def distributeCandies(self, n: int, limit: int) -> int:
        count = 0
        for i in range(min(n, limit) + 1):
            for j in range(min(n - i, limit) + 1):
                k = n - i - j
                if 0 <= k <= limit:
                    count += 1
        return count

Source