medium10 pts · first answer countsdynamic-programmingbacktrackingdebugging
All results come out empty
This permutation code returns a list of empty arrays. Why?
function permute(nums) {
const out = [], path = [], used = []
const go = () => {
if (path.length === nums.length) { out.push(path); return }
for (let i = 0; i < nums.length; i++) {
if (used[i]) continue
used[i] = true; path.push(nums[i])
go()
path.pop(); used[i] = false
}
}
go()
return out
}Discussion 0
Join free to post in the discussion.
Related questions
- What a 504 from Nginx meansBackend Developer
- Python default list surpriseBackend Developer
- 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