Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

<< [42] Subset of an array that adds up to k >>

Given a list of integers S and a target number k, write a function that returns a subset of S that adds up to k. If such a subset cannot be made, then return null. Integers can appear more than once in the list. You may assume all numbers in the list are positive.

Example:

>>> coding_problem_42([12, 1, 61, 5, 9, 2], 24)
[12, 9, 2, 1]

>>> coding_problem_42([12, 1, 61, 5, 9, 2], 25)  # return None

>>> coding_problem_42([12, 1, 61, 5, 9, 2], 19)
[12, 5, 2]