Skip to content

Practice Distribute Candies Among Children II

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#2929
LeetCode Problem

Distribute Candies Among Children II

Problem Statement

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.

Source: Distribute Candies Among Children II on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
n = 5, limit = 2
Output
3

# Example 2

Input
n = 3, limit = 3
Output
10

Constraints

1 <= n <= 10^6
1 <= limit <= 10^6

Related LeetCode Problems

Practice more problems similar to Distribute Candies Among Children II.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.