ToolBox.Online

Combination Sum Calculator - Find Number Combinations

Find all combinations of numbers that add up to a target sum. Free online combination sum calculator with step-by-step results.

What is Combination Sum Calculator?

The combination sum problem asks: given a set of numbers and a target value, find all possible combinations of those numbers that add up exactly to the target. This is a classic problem in computer science and mathematics with practical applications in finance, resource allocation, and puzzle solving. For example, given the numbers [2, 3, 5] and a target of 8, the valid combinations are: [2, 2, 2, 2], [2, 3, 3], [3, 5]. Each combination sums to exactly 8. By default, numbers can be reused (like using 2 four times), but you can also restrict each number to single use. This problem appears in many real-world scenarios: making change with available coin denominations, finding which invoices add up to a payment amount, allocating resources that fit within a budget, or solving number puzzles and contest problems.

How to Use Combination Sum Calculator

Enter a set of candidate numbers (comma-separated, e.g., 2, 3, 5, 7) and a target sum (e.g., 10). Click "Calculate" to find all unique combinations that add up to the target. By default, each number can be reused multiple times. Toggle the "Use each number once" option to restrict to single use. Results are displayed as a clear list of all valid combinations.

How Combination Sum Calculator Works

The calculator uses a backtracking algorithm to systematically explore all possible combinations: 1. Sort the candidate numbers in ascending order 2. Start with an empty combination and the full target sum remaining 3. Try adding each candidate number to the current combination: • If the number equals the remaining sum, a valid combination is found • If the number is less than the remaining sum, recurse with the reduced target • If the number exceeds the remaining sum, skip it and all larger numbers (pruning) 4. Backtrack by removing the last number and trying the next candidate This approach efficiently prunes the search space — it skips branches that cannot possibly lead to a valid combination. The algorithm avoids duplicate combinations by only considering candidates at or after the current position in the sorted list. Results are limited to 500 combinations for performance in your browser. For most practical inputs, all valid combinations are found within milliseconds.

Common Use Cases

  • Finding which invoices, bills, or transactions add up to a specific total for accounting reconciliation
  • Calculating coin or bill combinations to make exact change for a given amount
  • Solving number puzzles and coding challenges (LeetCode, HackerRank, coding interviews)
  • Determining which items fit within a budget or weight limit (simplified knapsack problem)
  • Planning portion sizes or ingredient quantities that sum to a target measurement
  • Exploring combinatorial mathematics and understanding backtracking algorithms

Frequently Asked Questions

Can numbers be reused?

Yes, by default each candidate number can be used unlimited times. You can toggle "Use each number once" to restrict each number to a single use, which is useful for finding exact matches in a list of unique values like invoices or transactions.

What is the maximum input size?

For performance in the browser, we recommend keeping the candidate set under 20 numbers and the target sum under 1000. Larger inputs may produce thousands of combinations and take longer to compute.

What algorithm does this use?

The calculator uses a backtracking algorithm with pruning. It sorts the candidates first, then systematically explores all possible combinations while skipping branches that cannot possibly reach the target. This is the same approach used in computer science interviews and competitive programming.

Why are results limited to 500 combinations?

Large inputs can produce millions of combinations. The 500-combination limit keeps the tool responsive in your browser. For most practical problems (accounting, puzzles, resource allocation), the complete solution set is well under this limit.

Can I use negative numbers?

The calculator is designed for positive integers. Negative numbers create infinite combinations (you could keep adding and subtracting). If you need negative number support, filter your results based on additional constraints.

How is this different from permutations?

Combinations ignore order — [2, 3, 5] and [5, 3, 2] are the same combination. Permutations treat different orderings as distinct results. This calculator finds combinations only, which is what most practical use cases need.

Related Tools