Combinatorics
Intermediate
8 min

Stars and Bars

Count the ways to distribute identical items into distinct groups, with or without lower bounds.

1. The idea

Stars and bars counts the number of ways to write identical items as an ordered sum of non-negative integers: , . Picture stars in a row and bars inserted among them to divide the stars into groups; the count is .

When each group requires a minimum count , substitute to reduce back to the non-negative case with a smaller total, , then apply the same formula.

This method applies whenever items are indistinguishable and only the count per category matters — distributing identical candies to children, allocating indistinguishable orders across price levels, and similar problems.

2. Why it matters

Stars and bars converts a distribution-counting problem into a single binomial coefficient, and the lower-bound shift technique is one of the most frequently reused tricks in quant interviews.

3. Core mathematics

Non-negative integer solutions

Number of solutions to with .

Positive integer solutions

Each ; equivalent to substituting .

General lower bound shift

4. How to recognize it

Think of this when…

  • Distributing identical items among distinct boxes, people, or categories.
  • Counting integer solutions to an equation like .
  • Minimum quantities per category ('each person gets at least one') signal the lower-bound shift.
  • Order allocation, inventory splitting, or dice-sum counting problems.

5. Worked example

Worked example

How many ways can 10 identical candies be distributed among 4 children so that each child gets at least 1 candy?

  1. 1

    Set up the equation: with each .

  2. 2

    Substitute , so .

  3. 3

    Apply the non-negative stars and bars formula with , .

  4. Answer: 84 ways.

6. Common mistakes

  • Using directly when there's a positivity constraint, without first shifting variables.
  • Mixing up with — they're equal, but it's easy to plug in the wrong pair of numbers if not careful.
  • Applying stars and bars when items are actually distinguishable (it only counts distributions of identical items).
  • Forgetting to subtract the total lower bound from before applying the formula.

7. Quick check

How many non-negative integer solutions are there to ?

How many ways to distribute 8 identical coins to 3 people so each gets at least 2?

8. Practice

12 QuantSolve questions use this concept.

Practice this concept

9. Related methods