MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / backtrack

Function backtrack

go/0077-combinations.go:1–13  ·  view source on GitHub ↗
(n, k, start int, arr []int, ans *[][]int)

Source from the content-addressed store, hash-verified

1func backtrack(n, k, start int, arr []int, ans *[][]int) {
2 if len(arr) == k {
3 comb := make([]int, k)
4 copy(comb, arr)
5 *ans = append(*ans, comb)
6 return
7 }
8 for i := start; i <= n-k+(len(arr)+1); i++ {
9 arr = append(arr, i)
10 backtrack(n, k, i+1, arr, ans)
11 arr = arr[:len(arr)-1]
12 }
13}
14
15func combine(n int, k int) [][]int {
16 ans := [][]int{}

Callers 12

permuteFunction · 0.70
permuteUniqueFunction · 0.70
partitionFunction · 0.70
restoreIpAddressesFunction · 0.70
combineFunction · 0.70
combinationSum2Function · 0.70
letterCombinationsFunction · 0.70
subsetsFunction · 0.70
solveNQueensFunction · 0.70
generateParenthesisFunction · 0.70
combinationSumFunction · 0.70
subsetsWithDupFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected