> ## Documentation Index
> Fetch the complete documentation index at: https://leetcode-py.wisl.dev/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> leetcode-py is a Python LeetCode practice environment generator with one CLI: lcpy. It is not a service or platform.
> Each problem is a directory under leetcode/ with README.md, solution.py, test_solution.py, helpers.py, and playground.ipynb. lcpy gen creates them from JSON templates bundled with the package.
> Examples are backed by tests; copy them verbatim.

# Backtracking in Python with Tests

> All 78 Backtracking LeetCode problems with tested Python solutions.

Backtracking holds 78 problems (3 Easy, 56 Medium, 19 Hard).
Generate any of them into the current directory with `lcpy gen -n <number>`.

<div className="sd-catalog-table">
  | # | Problem | Difficulty | Solution |
  | - | - | - | - |
  | 17 | [Letter Combinations of a Phone Number](/problems/letter-combinations-of-a-phone-number) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/letter_combinations_of_a_phone_number/solution.py) |
  | 22 | [Generate Parentheses](/problems/generate-parentheses) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/generate_parentheses/solution.py) |
  | 37 | [Sudoku Solver](/problems/sudoku-solver) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/sudoku_solver/solution.py) |
  | 39 | [Combination Sum](/problems/combination-sum) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/combination_sum/solution.py) |
  | 40 | [Combination Sum II](/problems/combination-sum-ii) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/combination_sum_ii/solution.py) |
  | 46 | [Permutations](/problems/permutations) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/permutations/solution.py) |
  | 47 | [Permutations II](/problems/permutations-ii) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/permutations_ii/solution.py) |
  | 51 | [N-Queens](/problems/n-queens) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/n_queens/solution.py) |
  | 52 | [N-Queens II](/problems/n-queens-ii) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/n_queens_ii/solution.py) |
  | 77 | [Combinations](/problems/combinations) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/combinations/solution.py) |
  | 78 | [Subsets](/problems/subsets) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/subsets/solution.py) |
  | 79 | [Word Search](/problems/word-search) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/word_search/solution.py) |
  | 89 | [Gray Code](/problems/gray-code) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/gray_code/solution.py) |
  | 90 | [Subsets II](/problems/subsets-ii) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/subsets_ii/solution.py) |
  | 93 | [Restore IP Addresses](/problems/restore-ip-addresses) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/restore_ip_addresses/solution.py) |
  | 95 | [Unique Binary Search Trees II](/problems/unique-binary-search-trees-ii) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/unique_binary_search_trees_ii/solution.py) |
  | 113 | [Path Sum II](/problems/path-sum-ii) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/path_sum_ii/solution.py) |
  | 126 | [Word Ladder II](/problems/word-ladder-ii) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/word_ladder_ii/solution.py) |
  | 131 | [Palindrome Partitioning](/problems/palindrome-partitioning) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/palindrome_partitioning/solution.py) |
  | 140 | [Word Break II](/problems/word-break-ii) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/word_break_ii/solution.py) |
  | 212 | [Word Search II](/problems/word-search-ii) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/word_search_ii/solution.py) |
  | 216 | [Combination Sum III](/problems/combination-sum-iii) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/combination_sum_iii/solution.py) |
  | 254 | [Factor Combinations](/problems/factor-combinations) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/factor_combinations/solution.py) |
  | 257 | [Binary Tree Paths](/problems/binary-tree-paths) | Easy | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/binary_tree_paths/solution.py) |
  | 267 | [Palindrome Permutation II](/problems/palindrome-permutation-ii) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/palindrome_permutation_ii/solution.py) |
  | 282 | [Expression Add Operators](/problems/expression-add-operators) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/expression_add_operators/solution.py) |
  | 291 | [Word Pattern II](/problems/word-pattern-ii) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/word_pattern_ii/solution.py) |
  | 294 | [Flip Game II](/problems/flip-game-ii) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/flip_game_ii/solution.py) |
  | 301 | [Remove Invalid Parentheses](/problems/remove-invalid-parentheses) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/remove_invalid_parentheses/solution.py) |
  | 306 | [Additive Number](/problems/additive-number) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/additive_number/solution.py) |
  | 320 | [Generalized Abbreviation](/problems/generalized-abbreviation) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/generalized_abbreviation/solution.py) |
  | 351 | [Android Unlock Patterns](/problems/android-unlock-patterns) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/android_unlock_patterns/solution.py) |
  | 357 | [Count Numbers with Unique Digits](/problems/count-numbers-with-unique-digits) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/count_numbers_with_unique_digits/solution.py) |
  | 401 | [Binary Watch](/problems/binary-watch) | Easy | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/binary_watch/solution.py) |
  | 411 | [Minimum Unique Word Abbreviation](/problems/minimum-unique-word-abbreviation) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/minimum_unique_word_abbreviation/solution.py) |
  | 425 | [Word Squares](/problems/word-squares) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/word_squares/solution.py) |
  | 465 | [Optimal Account Balancing](/problems/optimal-account-balancing) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/optimal_account_balancing/solution.py) |
  | 473 | [Matchsticks to Square](/problems/matchsticks-to-square) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/matchsticks_to_square/solution.py) |
  | 489 | [Robot Room Cleaner](/problems/robot-room-cleaner) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/robot_room_cleaner/solution.py) |
  | 491 | [Non-decreasing Subsequences](/problems/non-decreasing-subsequences) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/non_decreasing_subsequences/solution.py) |
  | 494 | [Target Sum](/problems/target-sum) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/target_sum/solution.py) |
  | 526 | [Beautiful Arrangement](/problems/beautiful-arrangement) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/beautiful_arrangement/solution.py) |
  | 638 | [Shopping Offers](/problems/shopping-offers) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/shopping_offers/solution.py) |
  | 679 | [24 Game](/problems/game-24) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/game_24/solution.py) |
  | 681 | [Next Closest Time](/problems/next-closest-time) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/next_closest_time/solution.py) |
  | 691 | [Stickers to Spell Word](/problems/stickers-to-spell-word) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/stickers_to_spell_word/solution.py) |
  | 698 | [Partition to K Equal Sum Subsets](/problems/partition-to-k-equal-sum-subsets) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/partition_to_k_equal_sum_subsets/solution.py) |
  | 756 | [Pyramid Transition Matrix](/problems/pyramid-transition) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/pyramid_transition/solution.py) |
  | 784 | [Letter Case Permutation](/problems/letter-case-permutation) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/letter_case_permutation/solution.py) |
  | 797 | [All Paths From Source to Target](/problems/all-paths-source-target) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/all_paths_source_target/solution.py) |
  | 816 | [Ambiguous Coordinates](/problems/ambiguous-coordinates) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/ambiguous_coordinates/solution.py) |
  | 842 | [Split Array into Fibonacci Sequence](/problems/split-into-fibonacci-sequence) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/split_into_fibonacci_sequence/solution.py) |
  | 949 | [Largest Time for Given Digits](/problems/largest-time-for-given-digits) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/largest_time_for_given_digits/solution.py) |
  | 967 | [Numbers With Same Consecutive Differences](/problems/numbers-with-same-consecutive-differences) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/numbers_with_same_consecutive_differences/solution.py) |
  | 980 | [Unique Paths III](/problems/unique-paths-iii) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/unique_paths_iii/solution.py) |
  | 988 | [Smallest String Starting From Leaf](/problems/smallest-string-starting-from-leaf) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/smallest_string_starting_from_leaf/solution.py) |
  | 996 | [Number of Squareful Arrays](/problems/number-of-squareful-arrays) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/number_of_squareful_arrays/solution.py) |
  | 1079 | [Letter Tile Possibilities](/problems/letter-tile-possibilities) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/letter_tile_possibilities/solution.py) |
  | 1087 | [Brace Expansion](/problems/brace-expansion) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/brace_expansion/solution.py) |
  | 1088 | [Confusing Number II](/problems/confusing-number-ii) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/confusing_number_ii/solution.py) |
  | 1215 | [Stepping Numbers](/problems/stepping-numbers) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/stepping_numbers/solution.py) |
  | 1219 | [Path with Maximum Gold](/problems/path-with-maximum-gold) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/path_with_maximum_gold/solution.py) |
  | 1239 | [Maximum Length of a Concatenated String with Unique Characters](/problems/maximum-length-of-a-concatenated-string-with-unique-characters) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/maximum_length_of_a_concatenated_string_with_unique_characters/solution.py) |
  | 1255 | [Maximum Score Words Formed by Letters](/problems/maximum-score-words-formed-by-letters) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/maximum_score_words_formed_by_letters/solution.py) |
  | 1258 | [Synonymous Sentences](/problems/synonymous-sentences) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/synonymous_sentences/solution.py) |
  | 1415 | [The k-th Lexicographical String of All Happy Strings of Length n](/problems/k-th-lexicographical-string-of-all-happy-strings-of-length-n) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/k_th_lexicographical_string_of_all_happy_strings_of_length_n/solution.py) |
  | 1593 | [Split a String Into the Max Number of Unique Substrings](/problems/split-a-string-into-the-max-number-of-unique-substrings) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/split_a_string_into_the_max_number_of_unique_substrings/solution.py) |
  | 1718 | [Construct the Lexicographically Largest Valid Sequence](/problems/construct-the-lexicographically-largest-valid-sequence) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/construct_the_lexicographically_largest_valid_sequence/solution.py) |
  | 1780 | [Check if Number is a Sum of Powers of Three](/problems/check-if-number-is-a-sum-of-powers-of-three) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/check_if_number_is_a_sum_of_powers_of_three/solution.py) |
  | 1799 | [Maximize Score After N Operations](/problems/maximize-score-after-n-operations) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/maximize_score_after_n_operations/solution.py) |
  | 1849 | [Splitting a String Into Descending Consecutive Values](/problems/splitting-a-string-into-descending-consecutive-values) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/splitting_a_string_into_descending_consecutive_values/solution.py) |
  | 1863 | [Sum of All Subset XOR Totals](/problems/sum-of-all-subset-xor-totals) | Easy | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/sum_of_all_subset_xor_totals/solution.py) |
  | 1980 | [Find Unique Binary String](/problems/find-unique-binary-string) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/find_unique_binary_string/solution.py) |
  | 2002 | [Maximum Product of the Length of Two Palindromic Subsequences](/problems/maximum-product-of-the-length-of-two-palindromic-subsequences) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/maximum_product_of_the_length_of_two_palindromic_subsequences/solution.py) |
  | 2044 | [Count Number of Maximum Bitwise-OR Subsets](/problems/count-number-of-maximum-bitwise-or-subsets) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/count_number_of_maximum_bitwise_or_subsets/solution.py) |
  | 2375 | [Construct Smallest Number From DI String](/problems/construct-smallest-number-from-di-string) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/construct_smallest_number_from_di_string/solution.py) |
  | 2597 | [The Number of Beautiful Subsets](/problems/the-number-of-beautiful-subsets) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/the_number_of_beautiful_subsets/solution.py) |
  | 2698 | [Find the Punishment Number of an Integer](/problems/find-the-punishment-number-of-an-integer) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/find_the_punishment_number_of_an_integer/solution.py) |
</div>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.