MCPcopy
hub / github.com/keon/algorithms / _backtrack

Function _backtrack

algorithms/backtracking/subsets_unique.py:35–48  ·  view source on GitHub ↗

Recursive helper that includes or excludes each element.

(
    found: set[tuple[int, ...]],
    nums: list[int],
    stack: list[int],
    position: int,
)

Source from the content-addressed store, hash-verified

33
34
35def _backtrack(
36 found: set[tuple[int, ...]],
37 nums: list[int],
38 stack: list[int],
39 position: int,
40) -> None:
41 """Recursive helper that includes or excludes each element."""
42 if position == len(nums):
43 found.add(tuple(stack))
44 else:
45 stack.append(nums[position])
46 _backtrack(found, nums, stack, position + 1)
47 stack.pop()
48 _backtrack(found, nums, stack, position + 1)

Callers 1

subsets_uniqueFunction · 0.70

Calls 2

addMethod · 0.80
popMethod · 0.45

Tested by

no test coverage detected