chore: merge "Added backtracking sum of subset (#702)"

* sum of subset algorithm

* set returns comment

* fix comment

* add resource url to comments

* separate test to different file and format
This commit is contained in:
Suaze9
2021-09-30 22:48:49 -06:00
committed by GitHub
parent ee605b7694
commit dd19680261
2 changed files with 82 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
import { sumOfSubset } from '../SumOfSubset'
describe('SumOfSubset', () => {
it('should return the subsets that add up to the given number', () => {
// W = [2, 5, 7, 8, 12, 16, 23, 40]
// K = 25
const nums = [2, 5, 7, 8, 12, 16, 23, 40]
const subsets = sumOfSubset(nums, [], 0, 0, 25)
expect(subsets).toEqual([
[2, 7, 16],
[2, 23],
[5, 8, 12]
])
})
})