You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
combinationSum fails with Maximum call stack size exceeded.
It seems that there is an infinite recursion in it.
Step to reproduce: combinationSum([0], 1)
Bug 1: presence of 0 produces an infinite loop
Bug 2: presence of small entries compared to target produces a stack size exceeded - combinationSum([1], 100000)
Fix
I can issue a PR with the fix.
How did I find it?
Thanks to property based testing framework fast-check.
The property was the following:
importfcfrom'fast-check';fc.assert(fc.property(fc.set(fc.nat()),fc.nat(),(elements,target)=>{constcombinations=combinationSum(elements,target);constcombinationsStr=combinations.map(arr=>arr.join(','));// no duplicatesexpect([...newSet(combinationsStr)]).toEqual(combinationsStr);// right sumfor(constcombofcombinations)expect(comb.reduce((a,b)=>a+b,0)).toBe(target);}))
Or:
for any elements - array of unique positive integers, target - positive integer
the output of combinationSum(elements, target) does not contain any duplicates
and all its entries sum to target
The text was updated successfully, but these errors were encountered:
Details:
combinationSum
fails withMaximum call stack size exceeded
.It seems that there is an infinite recursion in it.
Step to reproduce:
combinationSum([0], 1)
Bug 1: presence of
0
produces an infinite loopBug 2: presence of small entries compared to target produces a
stack size exceeded
-combinationSum([1], 100000)
Fix
I can issue a PR with the fix.
How did I find it?
Thanks to property based testing framework fast-check.
The property was the following:
Or:
The text was updated successfully, but these errors were encountered: