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

# Hard LeetCode Problems in Python, Part 2

> All 276 Hard LeetCode problems with tested Python solutions. Part 2 of 2: problems 201-276.

Hard holds 276 problems.

| # | Problem | Difficulty | Solution |
| - | - | - | - |
| 996 | [Number of Squareful Arrays](https://leetcode-py.wisl.dev/problems/number-of-squareful-arrays) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/number_of_squareful_arrays/solution.py) |
| 1000 | [Minimum Cost to Merge Stones](https://leetcode-py.wisl.dev/problems/minimum-cost-to-merge-stones) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/minimum_cost_to_merge_stones/solution.py) |
| 1001 | [Grid Illumination](https://leetcode-py.wisl.dev/problems/grid-illumination) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/grid_illumination/solution.py) |
| 1028 | [Recover a Tree From Preorder Traversal](https://leetcode-py.wisl.dev/problems/recover-a-tree-from-preorder-traversal) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/recover_a_tree_from_preorder_traversal/solution.py) |
| 1074 | [Number of Submatrices That Sum to Target](https://leetcode-py.wisl.dev/problems/number-of-submatrices-that-sum-to-target) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/number_of_submatrices_that_sum_to_target/solution.py) |
| 1088 | [Confusing Number II](https://leetcode-py.wisl.dev/problems/confusing-number-ii) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/confusing_number_ii/solution.py) |
| 1092 | [Shortest Common Supersequence](https://leetcode-py.wisl.dev/problems/shortest-common-supersequence) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/shortest_common_supersequence/solution.py) |
| 1095 | [Find in Mountain Array](https://leetcode-py.wisl.dev/problems/find-in-mountain-array) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/find_in_mountain_array/solution.py) |
| 1106 | [Parsing A Boolean Expression](https://leetcode-py.wisl.dev/problems/parsing-a-boolean-expression) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/parsing_a_boolean_expression/solution.py) |
| 1121 | [Divide Array Into Increasing Sequences](https://leetcode-py.wisl.dev/problems/divide-array-into-increasing-sequences) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/divide_array_into_increasing_sequences/solution.py) |
| 1168 | [Optimize Water Distribution in a Village](https://leetcode-py.wisl.dev/problems/optimize-water-distribution-in-a-village) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/optimize_water_distribution_in_a_village/solution.py) |
| 1183 | [Maximum Number of Ones](https://leetcode-py.wisl.dev/problems/maximum-number-of-ones) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/maximum_number_of_ones/solution.py) |
| 1216 | [Valid Palindrome III](https://leetcode-py.wisl.dev/problems/valid-palindrome-iii) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/valid_palindrome_iii/solution.py) |
| 1220 | [Count Vowels Permutation](https://leetcode-py.wisl.dev/problems/count-vowels-permutation) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/count_vowels_permutation/solution.py) |
| 1231 | [Divide Chocolate](https://leetcode-py.wisl.dev/problems/divide-chocolate) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/divide_chocolate/solution.py) |
| 1235 | [Maximum Profit in Job Scheduling](https://leetcode-py.wisl.dev/problems/maximum-profit-in-job-scheduling) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/maximum_profit_in_job_scheduling/solution.py) |
| 1246 | [Palindrome Removal](https://leetcode-py.wisl.dev/problems/palindrome-removal) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/palindrome_removal/solution.py) |
| 1255 | [Maximum Score Words Formed by Letters](https://leetcode-py.wisl.dev/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) |
| 1259 | [Handshakes That Don't Cross](https://leetcode-py.wisl.dev/problems/handshakes-that-dont-cross) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/handshakes_that_dont_cross/solution.py) |
| 1269 | [Number of Ways to Stay in the Same Place After Some Steps](https://leetcode-py.wisl.dev/problems/number-of-ways-to-stay-in-the-same-place-after-some-steps) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/number_of_ways_to_stay_in_the_same_place_after_some_steps/solution.py) |
| 1274 | [Number of Ships in a Rectangle](https://leetcode-py.wisl.dev/problems/number-of-ships-in-a-rectangle) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/number_of_ships_in_a_rectangle/solution.py) |
| 1289 | [Minimum Falling Path Sum II](https://leetcode-py.wisl.dev/problems/minimum-falling-path-sum-ii) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/minimum_falling_path_sum_ii/solution.py) |
| 1335 | [Minimum Difficulty of a Job Schedule](https://leetcode-py.wisl.dev/problems/minimum-difficulty-of-a-job-schedule) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/minimum_difficulty_of_a_job_schedule/solution.py) |
| 1359 | [Count All Valid Pickup and Delivery Options](https://leetcode-py.wisl.dev/problems/count-all-valid-pickup-and-delivery-options) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/count_all_valid_pickup_and_delivery_options/solution.py) |
| 1383 | [Maximum Performance of a Team](https://leetcode-py.wisl.dev/problems/maximum-performance-of-a-team) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/maximum_performance_of_a_team/solution.py) |
| 1406 | [Stone Game III](https://leetcode-py.wisl.dev/problems/stone-game-iii) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/stone_game_iii/solution.py) |
| 1425 | [Constrained Subsequence Sum](https://leetcode-py.wisl.dev/problems/constrained-subsequence-sum) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/constrained_subsequence_sum/solution.py) |
| 1463 | [Cherry Pickup II](https://leetcode-py.wisl.dev/problems/cherry-pickup-ii) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/cherry_pickup_ii/solution.py) |
| 1489 | [Find Critical and Pseudo-Critical Edges in Minimum Spanning Tree](https://leetcode-py.wisl.dev/problems/find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/find_critical_and_pseudo_critical_edges_in_minimum_spanning_tree/solution.py) |
| 1526 | [Minimum Number of Increments on Subarrays to Form a Target Array](https://leetcode-py.wisl.dev/problems/minimum-number-of-increments-on-subarrays-to-form-a-target-array) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/minimum_number_of_increments_on_subarrays_to_form_a_target_array/solution.py) |
| 1531 | [String Compression II](https://leetcode-py.wisl.dev/problems/string-compression-ii) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/string_compression_ii/solution.py) |
| 1547 | [Minimum Cost to Cut a Stick](https://leetcode-py.wisl.dev/problems/minimum-cost-to-cut-a-stick) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/minimum_cost_to_cut_a_stick/solution.py) |
| 1553 | [Minimum Number of Days to Eat N Oranges](https://leetcode-py.wisl.dev/problems/minimum-number-of-days-to-eat-n-oranges) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/minimum_number_of_days_to_eat_n_oranges/solution.py) |
| 1568 | [Minimum Number of Days to Disconnect Island](https://leetcode-py.wisl.dev/problems/minimum-number-of-days-to-disconnect-island) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/minimum_number_of_days_to_disconnect_island/solution.py) |
| 1579 | [Remove Max Number of Edges to Keep Graph Fully Traversable](https://leetcode-py.wisl.dev/problems/remove-max-number-of-edges-to-keep-graph-fully-traversable) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/remove_max_number_of_edges_to_keep_graph_fully_traversable/solution.py) |
| 1611 | [Minimum One Bit Operations to Make Integers Zero](https://leetcode-py.wisl.dev/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) |
| 1639 | [Number of Ways to Form a Target String Given a Dictionary](https://leetcode-py.wisl.dev/problems/number-of-ways-to-form-a-target-string-given-a-dictionary) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/number_of_ways_to_form_a_target_string_given_a_dictionary/solution.py) |
| 1671 | [Minimum Number of Removals to Make Mountain Array](https://leetcode-py.wisl.dev/problems/minimum-number-of-removals-to-make-mountain-array) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/minimum_number_of_removals_to_make_mountain_array/solution.py) |
| 1675 | [Minimize Deviation in Array](https://leetcode-py.wisl.dev/problems/minimize-deviation-in-array) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/minimize_deviation_in_array/solution.py) |
| 1793 | [Maximum Score of a Good Subarray](https://leetcode-py.wisl.dev/problems/maximum-score-of-a-good-subarray) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/maximum_score_of_a_good_subarray/solution.py) |
| 1799 | [Maximize Score After N Operations](https://leetcode-py.wisl.dev/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) |
| 1851 | [Minimum Interval to Include Each Query](https://leetcode-py.wisl.dev/problems/minimum-interval-to-include-each-query) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/minimum_interval_to_include_each_query/solution.py) |
| 1857 | [Largest Color Value in a Directed Graph](https://leetcode-py.wisl.dev/problems/largest-color-value-in-a-directed-graph) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/largest_color_value_in_a_directed_graph/solution.py) |
| 1866 | [Number of Ways to Rearrange Sticks With K Sticks Visible](https://leetcode-py.wisl.dev/problems/rearrange-sticks) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/rearrange_sticks/solution.py) |
| 1944 | [Number of Visible People in a Queue](https://leetcode-py.wisl.dev/problems/number-of-visible-people-in-a-queue) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/number_of_visible_people_in_a_queue/solution.py) |
| 1964 | [Find the Longest Valid Obstacle Course at Each Position](https://leetcode-py.wisl.dev/problems/find-the-longest-valid-obstacle-course-at-each-position) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/find_the_longest_valid_obstacle_course_at_each_position/solution.py) |
| 2009 | [Minimum Number of Operations to Make Array Continuous](https://leetcode-py.wisl.dev/problems/minimum-number-of-operations-to-make-array-continuous) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/minimum_number_of_operations_to_make_array_continuous/solution.py) |
| 2040 | [Kth Smallest Product of Two Sorted Arrays](https://leetcode-py.wisl.dev/problems/kth-smallest-product-of-two-sorted-arrays) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/kth_smallest_product_of_two_sorted_arrays/solution.py) |
| 2045 | [Second Minimum Time to Reach Destination](https://leetcode-py.wisl.dev/problems/second-minimum-time-to-reach-destination) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/second_minimum_time_to_reach_destination/solution.py) |
| 2050 | [Parallel Courses III](https://leetcode-py.wisl.dev/problems/parallel-courses-iii) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/parallel_courses_iii/solution.py) |
| 2092 | [Find All People With Secret](https://leetcode-py.wisl.dev/problems/find-all-people-with-secret) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/find_all_people_with_secret/solution.py) |
| 2127 | [Maximum Employees to Be Invited to a Meeting](https://leetcode-py.wisl.dev/problems/maximum-employees-to-be-invited-to-a-meeting) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/maximum_employees_to_be_invited_to_a_meeting/solution.py) |
| 2147 | [Number of Ways to Divide a Long Corridor](https://leetcode-py.wisl.dev/problems/number-of-ways-to-divide-a-long-corridor) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/number_of_ways_to_divide_a_long_corridor/solution.py) |
| 2218 | [Maximum Value of K Coins From Piles](https://leetcode-py.wisl.dev/problems/maximum-value-of-k-coins-from-piles) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/maximum_value_of_k_coins_from_piles/solution.py) |
| 2251 | [Number of Flowers in Full Bloom](https://leetcode-py.wisl.dev/problems/number-of-flowers-in-full-bloom) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/number_of_flowers_in_full_bloom/solution.py) |
| 2290 | [Minimum Obstacle Removal to Reach Corner](https://leetcode-py.wisl.dev/problems/minimum-obstacle-removal-to-reach-corner) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/minimum_obstacle_removal_to_reach_corner/solution.py) |
| 2306 | [Naming a Company](https://leetcode-py.wisl.dev/problems/naming-a-company) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/naming_a_company/solution.py) |
| 2392 | [Build a Matrix With Conditions](https://leetcode-py.wisl.dev/problems/build-a-matrix-with-conditions) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/build_a_matrix_with_conditions/solution.py) |
| 2402 | [Meeting Rooms III](https://leetcode-py.wisl.dev/problems/meeting-rooms-iii) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/meeting_rooms_iii/solution.py) |
| 2416 | [Sum of Prefix Scores of Strings](https://leetcode-py.wisl.dev/problems/sum-of-prefix-scores-of-strings) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/sum_of_prefix_scores_of_strings/solution.py) |
| 2421 | [Number of Good Paths](https://leetcode-py.wisl.dev/problems/number-of-good-paths) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/number_of_good_paths/solution.py) |
| 2493 | [Divide Nodes Into the Maximum Number of Groups](https://leetcode-py.wisl.dev/problems/divide-nodes-into-the-maximum-number-of-groups) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/divide_nodes_into_the_maximum_number_of_groups/solution.py) |
| 2503 | [Maximum Number of Points From Grid Queries](https://leetcode-py.wisl.dev/problems/maximum-number-of-points-from-grid-queries) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/maximum_number_of_points_from_grid_queries/solution.py) |
| 2534 | [Time Taken to Cross the Door](https://leetcode-py.wisl.dev/problems/time-taken-to-cross-the-door) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/time_taken_to_cross_the_door/solution.py) |
| 2551 | [Put Marbles in Bags](https://leetcode-py.wisl.dev/problems/put-marbles-in-bags) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/put_marbles_in_bags/solution.py) |
| 2577 | [Minimum Time to Visit a Cell In a Grid](https://leetcode-py.wisl.dev/problems/minimum-time-to-visit-a-cell-in-a-grid) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/minimum_time_to_visit_a_cell_in_a_grid/solution.py) |
| 2709 | [Greatest Common Divisor Traversal](https://leetcode-py.wisl.dev/problems/greatest-common-divisor-traversal) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/greatest_common_divisor_traversal/solution.py) |
| 2742 | [Painting the Walls](https://leetcode-py.wisl.dev/problems/painting-the-walls) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/painting_the_walls/solution.py) |
| 2751 | [Robot Collisions](https://leetcode-py.wisl.dev/problems/robot-collisions) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/robot_collisions/solution.py) |
| 2818 | [Apply Operations to Maximize Score](https://leetcode-py.wisl.dev/problems/apply-operations-to-maximize-score) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/apply_operations_to_maximize_score/solution.py) |
| 2872 | [Maximum Number of K-Divisible Components](https://leetcode-py.wisl.dev/problems/maximum-number-of-k-divisible-components) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/maximum_number_of_k_divisible_components/solution.py) |
| 2940 | [Find Building Where Alice and Bob Can Meet](https://leetcode-py.wisl.dev/problems/find-building-where-alice-and-bob-can-meet) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/find_building_where_alice_and_bob_can_meet/solution.py) |
| 3045 | [Count Prefix and Suffix Pairs II](https://leetcode-py.wisl.dev/problems/count-prefix-and-suffix-pairs-ii) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/count_prefix_and_suffix_pairs_ii/solution.py) |
| 3068 | [Find the Maximum Sum of Node Values](https://leetcode-py.wisl.dev/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) |
| 3108 | [Minimum Cost Walk in Weighted Graph](https://leetcode-py.wisl.dev/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) |
| 3203 | [Find Minimum Diameter After Merging Two Trees](https://leetcode-py.wisl.dev/problems/find-minimum-diameter-after-merging-two-trees) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/find_minimum_diameter_after_merging_two_trees/solution.py) |

Pages: [1](https://leetcode-py.wisl.dev/catalog/hard.md), 2


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