Przejdź do treści
Biblioteka skilli
Programowanie · Nauka i wyjaśnianie

dsa-backtracking-subsets-permutations-n-queens

/dsa-backtracking-subsets-permutations-n-queens

Przeszukuje wyczerpująco przestrzenie decyzji: generuje permutacje i kombinacje oraz rozwiązuje zagadki z ograniczeniami, np. N hetmanów.

Licencja
MIT
Ostatnia zmiana repozytorium
28.10.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
1
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
0
Przestarzałość

Brak sygnałów. Repozytorium zmienione 28.10.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Przeszukuje wyczerpująco przestrzenie decyzji: generuje permutacje i kombinacje oraz rozwiązuje zagadki z ograniczeniami, np. N hetmanów.

Oryginalny opis (EN)

Use this skill when exploring exhaustive decision spaces, generating permutations, combinations, or solving constraint satisfaction puzzles.

Jak działa

  1. When to use
  2. Core principles
  3. Step-by-step workflow
  4. Specifics & examples
  5. Common mistakes & pitfalls
  6. Verification checklist
  7. Related skills
Sekcje z nagłówków SKILL.md, w oryginale · 53 linii, 323 słów
Podgląd SKILL.md
---
name: dsa-backtracking-subsets-permutations-n-queens
description: Use this skill when exploring exhaustive decision spaces, generating permutations, combinations, or solving constraint satisfaction puzzles.
---
# DSA: Backtracking, Subsets, Permutations & N-Queens

## When to use
Use this skill when the problem demands finding all possible valid configurations, subsets, combinations, anagrams, or solving Sudoku and N-Queens puzzles.

## Core principles
- **Choose, Explore, Unchoose Pattern**: Append choice to state path, make recursive call, and explicitly revert the state (pop choice) upon return.
- **Pruning (Branch & Bound)**: Abandon fruitless search branches immediately via conditional checks before descending into recursive depth.
- **Duplicate Handling via Sorting**: To avoid generating duplicate subsets/combinations, sort the input first and skip adjacent duplicates: `if i > start and nums[i] == nums[i-1]: continue`.
- **Base Case Return Guarantees**: Always append a copy of the path `results.append(path[:])` rather than the mutable reference `path`.

## Step-by-step workflow
1. Sort input array if permutations/combinations contain duplicates.
2. Define `backtrack(start_index, current_path)` helper function.
3. Specify base condition: if valid state reached, `result.append(list(current_path))` and return.
4. Loop over candidates from `start_index` to `len(candidates)`.
5. Apply pruning conditions (skip duplicates or invalid placements).
6. Execute: `current_path.append(cand)` -> `backtrack(...)` -> `current_path.pop()`.

## Specifics & examples
```python
# Subsets with Duplicates (O(2^N) Time, O(N) Call Stack Space)
def subsets_with_dup(nums: list[int]) -> list[list[int]]:
    nums.sort()
    res, path = [], []
    def backtrack(start: int):
        res.append(list(path))
        for i in range(start, len(nums)):
            if i > start and nums[i] == nums[i - 1]:
                continue  # skip duplicate choices at same level
            path.append(nums[i])
            backtrack(i + 1)
            path.pop()  # revert state
    backtrack(0)
    return res
```

## Common mistakes & pitfalls
- Appending `res.append(path)` without copying, leaving all entries empty when backtracking finishes.
- Forgetting to pop from `path`, corrupting state across siblings.
- Failing to sort before pruning duplicates in combination sum problems.

## Verification checklist
- [ ] Result array stores detached copies (`path[:]` or `list(path)`).
- [ ] State is strictly reverted after each recursive invocation.
- [ ] Duplicate choices pruned cleanly using sorted adjacency checks.

## Related skills
- dsa-dynamic-programming-1d-memoization-tabulation
- dsa-trees-binary-search-tree-dfs-bfs
- coding-interview-communication-thinking-out-loud
- dsa-time-space-complexity-big-o-analysis

Wersje

W bazie nie ma innych skilli o nazwie dsa-backtracking-subsets-permutations-n-queens.

Migawka bazy z 13.11.2026 · wersja paczki d50ab7b76daf (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 1 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 100combinatorial
    Pomaga rozwiązywać problemy kombinatoryczne: permutacje, kombinacje, backtracking, branch and bound, generowanie podzbiorów i spełnianie ograniczeń, w tym N-Queens i Sudoku, na podstawie TAOCP Knutha.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.