medium10 pts · first answer countsdynamic-programmingbacktracking
Subsets when the input has repeats
You generate all unique subsets of [1, 2, 2]. After sorting, which rule inside the loop stops duplicate subsets?
function go(start, path) {
out.push([...path])
for (let i = start; i < nums.length; i++) {
// which check goes here?
path.push(nums[i]); go(i + 1, path); path.pop()
}
}Discussion 0
Join free to post in the discussion.
Related questions
- Signs that a problem suits DPBackend Developer
- What memoisation meansBackend Developer
- What tabulation meansBackend Developer
- Cost of plain recursive FibonacciBackend Developer
- Fibonacci after adding a cacheBackend Developer
- Recursion with no base caseBackend Developer
- Ways to climb five stairsBackend Developer
- Hidden memory cost of recursionBackend Developer