LeetCode: Combinations Solution
"Don't try" - Charles BukowskiImplementation
1var combine = function (n, k) {2 const res = []34 const recusion = (arr, start, k) => {5 if (k === 0) {6 res.push([...arr])7 return8 }910 for (let i = start; i <= n; i++) {11 arr.push(i)12 recusion(arr, i + 1, k - 1)13 arr.pop()14 }15 }1617 recusion([], 1, k)1819 return res20}
References
Comments
Loading comments...
Tags
leetcode
backtracking
Apply and earn a $2,500 bonus once you're hired on your first job!
Clients from the Fortune 500 to Silicon Valley startups
Choose your own rate, get paid on time
From hourly, part-time, to full-time positions
Flexible remote working environment
A lot of open JavaScript jobs!!
Fact corner: Referred talent are 5x more likely to pass the Toptal screening process than the average applicant.
Still hesitate? Read HoningJS author's guide on dealing with Toptal interview process.