> ## 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.

# Bit Manipulation in Python with Tests

> All 96 Bit Manipulation LeetCode problems with tested Python solutions.

Bit Manipulation holds 96 problems (24 Easy, 53 Medium, 19 Hard).
Generate any of them into the current directory with `lcpy gen -n <number>`.

<div className="sd-catalog-table">
  | # | Problem | Difficulty | Solution |
  | - | - | - | - |
  | 29 | [Divide Two Integers](/problems/divide-two-integers) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/divide_two_integers/solution.py) |
  | 67 | [Add Binary](/problems/add-binary) | Easy | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/add_binary/solution.py) |
  | 78 | [Subsets](/problems/subsets) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/subsets/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) |
  | 136 | [Single Number](/problems/single-number) | Easy | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/single_number/solution.py) |
  | 137 | [Single Number II](/problems/single-number-ii) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/single_number_ii/solution.py) |
  | 187 | [Repeated DNA Sequences](/problems/repeated-dna-sequences) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/repeated_dna_sequences/solution.py) |
  | 190 | [Reverse Bits](/problems/reverse-bits) | Easy | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/reverse_bits/solution.py) |
  | 191 | [Number of 1 Bits](/problems/number-of-1-bits) | Easy | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/number_of_1_bits/solution.py) |
  | 201 | [Bitwise AND of Numbers Range](/problems/bitwise-and-of-numbers-range) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/bitwise_and_of_numbers_range/solution.py) |
  | 222 | [Count Complete Tree Nodes](/problems/count-complete-tree-nodes) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/count_complete_tree_nodes/solution.py) |
  | 231 | [Power of Two](/problems/power-of-two) | Easy | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/power_of_two/solution.py) |
  | 260 | [Single Number III](/problems/single-number-iii) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/single_number_iii/solution.py) |
  | 266 | [Palindrome Permutation](/problems/palindrome-permutation) | Easy | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/palindrome_permutation/solution.py) |
  | 268 | [Missing Number](/problems/missing-number) | Easy | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/missing_number/solution.py) |
  | 287 | [Find the Duplicate Number](/problems/find-the-duplicate-number) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/find_the_duplicate_number/solution.py) |
  | 318 | [Maximum Product of Word Lengths](/problems/maximum-product-of-word-lengths) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/maximum_product_of_word_lengths/solution.py) |
  | 320 | [Generalized Abbreviation](/problems/generalized-abbreviation) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/generalized_abbreviation/solution.py) |
  | 338 | [Counting Bits](/problems/counting-bits) | Easy | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/counting_bits/solution.py) |
  | 342 | [Power of Four](/problems/power-of-four) | Easy | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/power_of_four/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) |
  | 371 | [Sum of Two Integers](/problems/sum-of-two-integers) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/sum_of_two_integers/solution.py) |
  | 389 | [Find the Difference](/problems/find-the-difference) | Easy | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/find_the_difference/solution.py) |
  | 393 | [UTF-8 Validation](/problems/utf-8-validation) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/utf_8_validation/solution.py) |
  | 397 | [Integer Replacement](/problems/integer-replacement) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/integer_replacement/solution.py) |
  | 401 | [Binary Watch](/problems/binary-watch) | Easy | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/binary_watch/solution.py) |
  | 405 | [Convert a Number to Hexadecimal](/problems/convert-a-number-to-hexadecimal) | Easy | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/convert_a_number_to_hexadecimal/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) |
  | 421 | [Maximum XOR of Two Numbers in an Array](/problems/maximum-xor-of-two-numbers-in-an-array) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/maximum_xor_of_two_numbers_in_an_array/solution.py) |
  | 461 | [Hamming Distance](/problems/hamming-distance) | Easy | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/hamming_distance/solution.py) |
  | 464 | [Can I Win](/problems/can-i-win) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/can_i_win/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) |
  | 476 | [Number Complement](/problems/number-complement) | Easy | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/number_complement/solution.py) |
  | 477 | [Total Hamming Distance](/problems/total-hamming-distance) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/total_hamming_distance/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) |
  | 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) |
  | 645 | [Set Mismatch](/problems/set-mismatch) | Easy | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/set_mismatch/solution.py) |
  | 672 | [Bulb Switcher II](/problems/bulb-switcher-ii) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/bulb_switcher_ii/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) |
  | 693 | [Binary Number with Alternating Bits](/problems/binary-number-with-alternating-bits) | Easy | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/binary_number_with_alternating_bits/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) |
  | 751 | [IP to CIDR](/problems/ip-to-cidr) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/ip_to_cidr/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) |
  | 762 | [Prime Number of Set Bits in Binary Representation](/problems/prime-number-of-set-bits-in-binary-representation) | Easy | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/prime_number_of_set_bits_in_binary_representation/solution.py) |
  | 779 | [K-th Symbol in Grammar](/problems/kth-symbol-in-grammar) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/kth_symbol_in_grammar/solution.py) |
  | 782 | [Transform to Chessboard](/problems/transform-to-chessboard) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/transform_to_chessboard/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) |
  | 805 | [Split Array With Same Average](/problems/split-array-with-same-average) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/split_array_with_same_average/solution.py) |
  | 810 | [Chalkboard XOR Game](/problems/chalkboard-xor-game) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/chalkboard_xor_game/solution.py) |
  | 832 | [Flipping an Image](/problems/flipping-an-image) | Easy | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/flipping_an_image/solution.py) |
  | 847 | [Shortest Path Visiting All Nodes](/problems/shortest-path-visiting-all-nodes) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/shortest_path_visiting_all_nodes/solution.py) |
  | 861 | [Score After Flipping Matrix](/problems/score-after-flipping-matrix) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/score_after_flipping_matrix/solution.py) |
  | 864 | [Shortest Path to Get All Keys](/problems/shortest-path-to-get-all-keys) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/shortest_path_to_get_all_keys/solution.py) |
  | 868 | [Binary Gap](/problems/binary-gap) | Easy | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/binary_gap/solution.py) |
  | 898 | [Bitwise ORs of Subarrays](/problems/bitwise-ors-of-subarrays) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/bitwise_ors_of_subarrays/solution.py) |
  | 943 | [Find the Shortest Superstring](/problems/find-the-shortest-superstring) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/find_the_shortest_superstring/solution.py) |
  | 957 | [Prison Cells After N Days](/problems/prison-cells-after-n-days) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/prison_cells_after_n_days/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) |
  | 982 | [Triples with Bitwise AND Equal To Zero](/problems/triples-with-bitwise-and-equal-to-zero) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/triples_with_bitwise_and_equal_to_zero/solution.py) |
  | 995 | [Minimum Number of K Consecutive Bit Flips](/problems/minimum-number-of-k-consecutive-bit-flips) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/minimum_number_of_k_consecutive_bit_flips/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) |
  | 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) |
  | 1310 | [XOR Queries of a Subarray](/problems/xor-queries-of-a-subarray) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/xor_queries_of_a_subarray/solution.py) |
  | 1371 | [Find the Longest Substring Containing Vowels in Even Counts](/problems/find-the-longest-substring-containing-vowels-in-even-counts) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/find_the_longest_substring_containing_vowels_in_even_counts/solution.py) |
  | 1442 | [Count Triplets That Can Form Two Arrays of Equal XOR](/problems/count-triplets-that-can-form-two-arrays-of-equal-xor) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/count_triplets_that_can_form_two_arrays_of_equal_xor/solution.py) |
  | 1457 | [Pseudo-Palindromic Paths in a Binary Tree](/problems/pseudo-palindromic-paths-in-a-binary-tree) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/pseudo_palindromic_paths_in_a_binary_tree/solution.py) |
  | 1461 | [Check If a String Contains All Binary Codes of Size K](/problems/check-if-a-string-contains-all-binary-codes-of-size-k) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/check_if_a_string_contains_all_binary_codes_of_size_k/solution.py) |
  | 1506 | [Find Root of N-Ary Tree](/problems/find-root-of-n-ary-tree) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/find_root_of_n_ary_tree/solution.py) |
  | 1611 | [Minimum One Bit Operations to Make Integers Zero](/problems/minimum-one-bit-operations-to-make-integers-zero) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/minimum_one_bit_operations_to_make_integers_zero/solution.py) |
  | 1684 | [Count the Number of Consistent Strings](/problems/count-the-number-of-consistent-strings) | Easy | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/count_the_number_of_consistent_strings/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) |
  | 1829 | [Maximum XOR for Each Query](/problems/maximum-xor-for-each-query) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/maximum_xor_for_each_query/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) |
  | 1930 | [Unique Length-3 Palindromic Subsequences](/problems/unique-length-3-palindromic-subsequences) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/unique_length_3_palindromic_subsequences/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) |
  | 2206 | [Divide Array Into Equal Pairs](/problems/divide-array-into-equal-pairs) | Easy | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/divide_array_into_equal_pairs/solution.py) |
  | 2220 | [Minimum Bit Flips to Convert Number](/problems/minimum-bit-flips-to-convert-number) | Easy | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/minimum_bit_flips_to_convert_number/solution.py) |
  | 2275 | [Largest Combination With Bitwise AND Greater Than Zero](/problems/largest-combination-with-bitwise-and-greater-than-zero) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/largest_combination_with_bitwise_and_greater_than_zero/solution.py) |
  | 2306 | [Naming a Company](/problems/naming-a-company) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/naming_a_company/solution.py) |
  | 2401 | [Longest Nice Subarray](/problems/longest-nice-subarray) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/longest_nice_subarray/solution.py) |
  | 2419 | [Longest Subarray With Maximum Bitwise AND](/problems/longest-subarray-with-maximum-bitwise-and) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/longest_subarray_with_maximum_bitwise_and/solution.py) |
  | 2425 | [Bitwise XOR of All Pairings](/problems/bitwise-xor-of-all-pairings) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/bitwise_xor_of_all_pairings/solution.py) |
  | 2429 | [Minimize XOR](/problems/minimize-xor) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/minimize_xor/solution.py) |
  | 2683 | [Neighboring Bitwise XOR](/problems/neighboring-bitwise-xor) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/neighboring_bitwise_xor/solution.py) |
  | 3011 | [Find if Array Can Be Sorted](/problems/find-if-array-can-be-sorted) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/find_if_array_can_be_sorted/solution.py) |
  | 3068 | [Find the Maximum Sum of Node Values](/problems/find-the-maximum-sum-of-node-values) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/find_the_maximum_sum_of_node_values/solution.py) |
  | 3097 | [Shortest Subarray With OR at Least K II](/problems/shortest-subarray-with-or-at-least-k-ii) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/shortest_subarray_with_or_at_least_k_ii/solution.py) |
  | 3108 | [Minimum Cost Walk in Weighted Graph](/problems/minimum-cost-walk-in-weighted-graph) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/minimum_cost_walk_in_weighted_graph/solution.py) |
  | 3133 | [Minimum Array End](/problems/minimum-array-end) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/minimum_array_end/solution.py) |
  | 3191 | [Minimum Operations to Make Binary Array Elements Equal to One I](/problems/minimum-operations-to-make-binary-array-elements-equal-to-one-i) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/minimum_operations_to_make_binary_array_elements_equal_to_one_i/solution.py) |
  | 3199 | [Count Triplets with Even XOR Set Bits I](/problems/count-triplets-with-even-xor-set-bits-i) | Easy | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/count_triplets_with_even_xor_set_bits_i/solution.py) |
</div>


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