All problems
Positive Composition Count
Problem
The number of compositions of n into exactly k positive ordered parts is C(n - 1, k - 1) when 1 <= k <= n.
Given n and k, return the count, or 0 when no such composition exists.
Hint
Place k - 1 dividers in the n - 1 gaps between units.
Test cases
case 1
in: [5,2]
expected: 4
case 2
in: [5,1]
expected: 1
case 3
in: [3,4]
expected: 0
Starter codePython
def positive_composition_count(n, k):
# Your code here
pass3 test cases · run your code against them in the editor