TuSimple | OA | SDE
Anonymous User
3470

Similiar to 216. Combination Sum III, but slightly different.

def CSum(k, iteration):

here the available number candidate can be 1~k, and their total sum(distinct set) should be k, with iteration constrain. Return number of distinct solution.

ex. CSum(7, 3) => 4
There are four possible combinations: [1, 1, 5], [1, 2, 4], [1, 3, 3], [2, 2, 3], so return 4.
(All possible combinations should sum up to k and its length equal to iteration)

But the number k and iteration may be really big, so using BFS will trigger time limit exceed, should use DP.

Anyone can point out a proper DP solution?

Comments (2)