All problems
Stars and Bars Count
Problem
The number of nonnegative integer solutions to x1 + ... + xk = n is C(n + k - 1, k - 1).
Given n and k >= 1, return the count.
Hint
Choosing positions of k - 1 separators among n + k - 1 slots.
Test cases
case 1
in: [3,2]
expected: 4
case 2
in: [5,3]
expected: 21
case 3
in: [0,4]
expected: 1
Starter codePython
def stars_and_bars_count(n, k):
# Your code here
pass3 test cases · run your code against them in the editor