Tomaz Kastrun knows if you can sum those together:
CanSum problem is a problem where a given array of integers (
nums
) and a target integer (target
), return boolean (TRUE \ FALSE) indicating, that theinteger can be calculated using two or more numbers in array
target
nums
.You may assume that each integer from the array can be used multiple times. You can also assume, that any integer (in
nums
or intarget
) is from 0 to +1e9 and the length of thenums
array is from 2 to 1000 elements.
Click through for an example of one brute-force solution, followed by a much faster solution.