Skip to content
RED SAG Skills
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()
  }
}
Choose one answer

Discussion 0

Join free to post in the discussion.

Related questions