MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / combination_sum_iv

Function combination_sum_iv

dynamic_programming/combination_sum_iv.py:26–42  ·  view source on GitHub ↗

Function checks the all possible combinations, and returns the count of possible combination in exponential Time Complexity. >>> combination_sum_iv([1,2,5], 5) 9

(array: list[int], target: int)

Source from the content-addressed store, hash-verified

24
25
26def combination_sum_iv(array: list[int], target: int) -> int:
27 """
28 Function checks the all possible combinations, and returns the count
29 of possible combination in exponential Time Complexity.
30
31 >>> combination_sum_iv([1,2,5], 5)
32 9
33 """
34
35 def count_of_possible_combinations(target: int) -> int:
36 if target < 0:
37 return 0
38 if target == 0:
39 return 1
40 return sum(count_of_possible_combinations(target - item) for item in array)
41
42 return count_of_possible_combinations(target)
43
44
45def combination_sum_iv_dp_array(array: list[int], target: int) -> int:

Callers 1

Calls 1

Tested by

no test coverage detected