Create a recursive function with arguments N and K in python 3 that does the following specifications: Using numbers ranging from 0 to 15 (inclusive), create all possible lists which sum up to K and have a length of N. Duplicated numbers are allowed as long as it fulfills the conditions above (this means [0,0,1], [0,1,0] and [1,0,0] are all correct outputs if K=1 and N=3) The function returns the number of created lists which follow the specifications mentioned. For example, given K=23 and N=2, the expected output of the function is 8. Constraints: 1) The time complexity must be O(n) or faster. Indicate the time complexity of created code as proof. (Redundant due to constraint above, but still it is important to note that the function must be able to finish in 9 seconds or less when N=10) 2) You are not allowed to use external libraries or itertools.
Create a recursive function with arguments N and K in python 3 that does the following specifications:
Using numbers ranging from 0 to 15 (inclusive), create all possible lists which sum up to K and have a length of N. Duplicated numbers are allowed as long as it fulfills the conditions above (this means [0,0,1], [0,1,0] and [1,0,0] are all correct outputs if K=1 and N=3) The function returns the number of created lists which follow the specifications mentioned.
For example, given K=23 and N=2, the expected output of the function is 8.
Constraints:
1) The time complexity must be O(n) or faster. Indicate the time complexity of created code as proof.
(Redundant due to constraint above, but still it is important to note that the function must be able to finish in 9 seconds or less when N=10)
2) You are not allowed to use external libraries or itertools.
Step by step
Solved in 4 steps with 2 images