FastPrepCount Combinations Using Weights One Through K
Problems/Count Combinations Using Weights One Through K

Count Combinations Using Weights One Through K

Confluent logoConfluent● MediumFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Confluent online assessment. The report leaves out the input limits and what a total of zero should give. Our version is about 95% the same as the reported question.

Given a nonnegative integer total and a positive integer k, count the combinations of integer weights 1 through k whose sum is exactly total.

  • You may use each weight any number of times.
  • A combination is determined by the number of copies of each weight. Different arrangements of the same weights count as one combination.
  • There is one combination for total = 0: selecting no weights.

Return the count modulo 10^9 + 7.

Function

countWeightCombinations(total: int, k: int) → int

Examples

Example 1

total = 8k = 2return = 5

The combinations are [1,1,1,1,1,1,1,1], [1,1,1,1,1,1,2], [1,1,1,1,2,2], [1,1,2,2,2], and [2,2,2,2].

Example 2

total = 5k = 3return = 5

The combinations are [1,1,1,1,1], [1,1,1,2], [1,2,2], [1,1,3], and [2,3].

Example 3

total = 3k = 8return = 3

The combinations are [1,1,1], [1,2], and [3]. Weights greater than 3 cannot appear in a sum of 3.

Constraints

  • 0 <= total <= 1000.
  • 1 <= k <= 1000.

More Confluent interview questions

  • Hard Disk Clustering CostOA · Seen Nov 2026
  • Last Object to Fall Off the TableOA · Seen Nov 2026
  • Sum Symmetric Pairwise RemaindersOA · Seen Nov 2026
  • 0/1 KnapsackOA · Seen Nov 2026
  • Reach Target BalanceOA · Seen Mar 2026
  • Tail N LinesOA · Seen Mar 2026
  • Implement tail -nPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Sudoku Board ValidationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Sudoku Puzzle SolverPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Match a Variadic Function SignaturePHONE SCREEN · Seen Oct 2026

Similar questions at other companies

  • Frog Paths Without Long RunsSusquehanna International Group (SIG) · OA
  • Count Routes Through Four Shop TypesOpenAI · OA
  • Count Digit Replacements with No Equal Adjacent DigitsMicrosoft · OA
  • Count Bounded Share TransactionsOptiver · OA
  • Count Strictly Increasing Subsequences of Length 3IBM · OA
  • Count Shipment SchedulesMorgan Stanley · OA
  • Replace '?' to Avoid Adjacent DuplicatesSalesforce · OA
  • Count Subsequences Without Three Equal-Parity Elements in a RowGoogle · OA
  • Binary Palindromic Subsequences of Length 5Citadel · OA
  • Count Equal-Frequency SubsequencesExpedia · OA
See Confluent hiring insights
Saved
class Solution {
    public int countWeightCombinations(int total, int k) {
        // write your code here
    }

}
Checking account…