Interview prep
Quant10 min read

Stars and Bars in CAT: Counting Integer Solutions, 3 Steps

Published November 27, 2026
Cover image with the headline Stars and bars counting integer solutions on a blue themed layout
Quant

Some CAT counting questions look like algebra and are really about sharing. How many ways can 10 identical chocolates go to 3 children? How many whole number solutions does x + y + z = 10 have? These are the same question in two costumes, and a single idea called stars and bars answers both in about twenty seconds. Without it, most candidates list cases until time runs out, and a list always misses a case.

This post gives the method in three steps, then works through the variations that CAT tends to add: a minimum for each variable, an upper limit on each variable, and an inequality instead of an equation. Every count below was checked by brute force, so you can trust the numbers when you practise.

If number system and counting are on your revision list, the CAT preparation planner can slot them into your remaining weeks.

Key Takeaways
  • Stars and bars counts the ways to split n identical items among k distinct boxes.
  • Non-negative solutions of x1 + x2 + ... + xk = n number C(n + k-1, k-1).
  • Positive solutions number C(n-1, k-1). Shift each variable down by its minimum first.
  • Upper limits need subtraction. Count everything, then remove the cases that break the limit.
  • An inequality becomes an equation by adding one slack variable.

The Idea Behind Stars and Bars

Picture 10 identical stars in a row. To split them among 3 children, you place 2 bars between the stars. The stars before the first bar go to child one, the stars between the bars go to child two, and the stars after the second bar go to child three. Every arrangement of 10 stars and 2 bars is one way of sharing, and every way of sharing is one arrangement.

So the question becomes: in how many ways can you arrange 12 symbols, of which 2 are bars? That is choosing the 2 positions for the bars out of 12, which is C(12, 2) = 66. A child can get zero stars, because two bars can sit side by side or at the very ends. That is why 66 counts the non-negative solutions of x + y + z = 10.

The general formula

For k variables and a total of n, you need k-1 bars and n stars, which makes n + k-1 symbols. Choose positions for the bars and you get C(n + k-1, k-1). The two features that must hold are that the items are identical and the boxes are distinct. If the chocolates were all different, this would be a different problem.

The Three Steps

Step 1: Confirm the items are identical and the boxes are distinct

Write the question as a sum. Whole number solutions of an equation are the cleanest case, because the value of each variable is just how many stars it gets. Chocolates to children, identical balls to distinct bags and coins to people all fit. Ask two questions: are the things being shared identical, and do the receivers have identities? If both answers are yes, stars and bars applies.

Step 2: Convert every condition to a non-negative one

The formula counts solutions where each variable can be zero or more. If a variable must be at least some minimum, subtract that minimum from the total and let the variable start again from zero. If every variable must be positive, subtract 1 for each. Positive solutions of x + y + z = 10 are therefore the non-negative solutions of a + b + c = 7, which is C(9, 2) = 36.

Step 3: Apply the formula, then deal with limits

Once everything is non-negative, apply C(n + k-1, k-1). If a variable also has an upper limit, count without the limit first and subtract the cases that break it. The next sections show each version.

Exam Tip

Before you compute anything, write n and k on your rough sheet. Most errors in this topic come from using the wrong n after a shift, not from the formula itself.

Worked Examples With Minimums

Example 1. Find the number of non-negative integer solutions of x + y + z = 10. Here n = 10 and k = 3, so the count is C(12, 2) = 66.

Example 2. Find the number of positive integer solutions of x + y + z = 15. Each variable is at least 1, so put x = a + 1, y = b + 1, z = c + 1. Then a + b + c = 12 with non-negative values, giving C(14, 2) = 91. The shortcut for all-positive cases is C(n-1, k-1) = C(14, 2), which matches.

Example 3. How many solutions does x + y + z = 20 have if x is at least 2, y is at least 3 and z is at least 4? The minimums add up to 9, so the leftover to distribute freely is 11. The count is C(13, 2) = 78.

Example 4. In how many ways can 8 identical chocolates be given to 4 children if every child gets at least one? Give each child one first, leaving 4 to share freely among 4 children: C(7, 3) = 35. Equivalently, C(n-1, k-1) = C(7, 3).

Condition on the variablesAdjust n toCount
All at least 0nC(n + k-1, k-1)
All at least 1n-kC(n-1, k-1)
Variable i at least m_in minus the sum of the m_iC(n-sum + k-1, k-1)
Sum at most nAdd a slack variableC(n + k, k)
Common Mistake

Shifting a variable but forgetting to shift the total. If x must be at least 2, you must also reduce the right-hand side by 2. Changing only the variable leaves the equation unbalanced and the count wrong.

When a Variable Has an Upper Limit

Upper limits are where CAT adds difficulty. Take this: how many solutions does x + y + z = 12 have if each variable is a whole number from 0 to 5?

First count everything with no limit: C(14, 2) = 91. Now remove the solutions where some variable is at least 6. For x at least 6, put x = 6 + a, which leaves a + y + z = 6 and C(8, 2) = 28 solutions. The same holds for y and z, so subtract 3 times 28 = 84. This removes too much, because a solution where two variables are both at least 6 was subtracted twice. Two variables at least 6 leaves a total of 0, which is 1 solution for each of the 3 pairs. Add those 3 back. Three variables at least 6 is impossible.

The count is 91 minus 84 plus 3 = 10. A direct check agrees: the triples are 5, 5, 2 in 3 orders, 5, 4, 3 in 6 orders, and 4, 4, 4 in 1 way, which makes 10.

CAT Shortcut

When the limit is tight, list directly. With a total of 12 and a maximum of 5 each, the three numbers must be large, so listing the few possibilities is faster than inclusion and exclusion. Use subtraction when the list would be long.

Choosing between subtraction and listing

If the limit removes most of the solutions, listing is quicker. If the limit removes only a small share, subtraction is quicker. A good habit is to estimate the size of the full count first. If it is in the hundreds and the answer you expect is small, list. If the limit barely bites, subtract.

Inequalities and the Slack Variable

Suppose the question asks for non-negative solutions of x + y + z + w at most 6. An inequality is not an equation, so add a slack variable s that soaks up the unused amount: x + y + z + w + s = 6 with all five variables non-negative. Now n = 6 and k = 5, giving C(10, 4) = 210. The slack variable turns every inequality into an equation, and the count matches a direct enumeration.

The same trick handles a lower inequality. For x + y + z at least 10 with each variable at most 6, flip the question with a complement or substitute each variable by 6 minus itself so that the inequality turns around.

Mentor Insight

Students often feel stars and bars is a formula to memorise. It is better to treat it as a picture. If you can see the stars and the bars, you can rebuild the formula in ten seconds in the exam, and you can adjust it when a condition changes.

Where CAT Hides This Idea

Counting integer solutions is the plain version. CAT often disguises it. Look for the wording below and ask whether the items are identical and the boxes distinct.

  • Distributing identical items such as balls, sweets, coins or tickets among distinct people or bags.
  • Non-negative or positive integer solutions of a linear equation.
  • Questions about the number of terms in the expansion of a multivariable expression such as (x + y + z) raised to a power.
  • Problems on the number of ways to choose a given number of items from several types when repetition is allowed.
  • Inequalities such as a + b + c at most 20 with whole number constraints.

The expansion case is worth a note. The number of distinct terms in (x + y + z) to the power 5 is the number of non-negative solutions of a + b + c = 5, which is C(7, 2) = 21. Each solution is the set of exponents of one term.

How to Practise This Topic

A short routine works better than a long one. Start with ten plain problems so that the formula feels automatic. Then add minimums, then limits, then inequalities. For every answer, write the value of n and k before using the formula, and keep a habit of checking a small case by hand.

  • Solve five plain problems and write n and k each time.
  • Solve five problems with minimums and check by shifting.
  • Solve three problems with an upper limit using subtraction.
  • Solve two inequality problems with a slack variable.
  • Check one answer in each group by listing a smaller version of the same problem.

For topic-wise questions on counting and number system, the number system practice page is a sensible place to build the habit. When your accuracy on a topic stays low across weeks, a strategy review can show whether the issue is the method or the time you give it.

Quick Check
  • Are the items identical and the boxes distinct?
  • Have I shifted both the variable and the total for every minimum?
  • If there is an upper limit, did I subtract and then add back the overlaps?
  • For an inequality, did I add the slack variable?

Common Traps in Stars and Bars

  • Using the formula when the items are different. Distinct items need a different method.
  • Counting solutions with positive values using the non-negative formula, or the reverse.
  • Forgetting that a limit on one variable changes the count even when the others are free.
  • Treating two arrangements as the same when the boxes are distinct. Child one getting 2 and child two getting 3 is different from the reverse.
  • Subtracting overlaps twice or not at all in an inclusion and exclusion step.

A reliable check is the small-case test. Reduce the numbers so that you can list every solution, apply your method, and compare. If the method works for x + y = 3, you can trust it for x + y = 30.

Another useful habit is to translate the answer back into words. If you computed C(9, 2) for positive solutions of x + y + z = 10 you should be able to say: there are 9 gaps between 10 stars, and I choose 2 of them for the bars. If the sentence does not make sense, the formula was probably the wrong one.

Summary

Stars and bars turns sharing problems into a choice of bar positions. Confirm the items are identical and the boxes distinct, move every condition to a non-negative form, apply C(n + k-1, k-1), and handle limits by subtraction.

Practise the four variations in order, check each with a small case, and the topic becomes a reliable source of quick marks.

Practise Number System and Counting

Work through topic-wise Quant questions and see how your accuracy on this chapter changes over time.

Open Number System Practice

Frequently Asked Questions About Stars and Bars in CAT

What is the stars and bars formula?

For non-negative integer solutions of x1 + x2 + ... + xk = n, the count is C(n + k-1, k-1). For positive solutions it is C(n-1, k-1).

Can stars and bars handle an upper limit on each variable?

Yes. Count all the solutions first, then subtract those that break the limit, adding back overlaps where two limits break together.

How do I count solutions of an inequality such as x + y + z at most 10?

Add a slack variable to turn the inequality into an equation. For three variables and a total of at most 10 you count solutions of four variables summing to 10.

When does stars and bars not apply?

When the items are different from each other, or when the boxes are not distinct. In those cases you need a different counting method.

From the Optima Learn product

Practice these Quant concepts, chapter by chapter

Thousands of CAT Quant practice questions by chapter and difficulty, each with a worked solution.

More from Quant