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

# Heap (Priority Queue) in Python with Tests

> All 85 Heap (Priority Queue) LeetCode problems with tested Python solutions.

Heap (Priority Queue) holds 85 problems (7 Easy, 44 Medium, 34 Hard).
Generate any of them into the current directory with `lcpy gen -n <number>`.

<div className="sd-catalog-table">
  | # | Problem | Difficulty | Solution |
  | - | - | - | - |
  | 23 | [Merge k Sorted Lists](/problems/merge-k-sorted-lists) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/merge_k_sorted_lists/solution.py) |
  | 215 | [Kth Largest Element in an Array](/problems/kth-largest-element-in-an-array) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/kth_largest_element_in_an_array/solution.py) |
  | 218 | [The Skyline Problem](/problems/the-skyline-problem) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/the_skyline_problem/solution.py) |
  | 239 | [Sliding Window Maximum](/problems/sliding-window-maximum) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/sliding_window_maximum/solution.py) |
  | 253 | [Meeting Rooms II](/problems/meeting-rooms-ii) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/meeting_rooms_ii/solution.py) |
  | 264 | [Ugly Number II](/problems/ugly-number-ii) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/ugly_number_ii/solution.py) |
  | 272 | [Closest Binary Search Tree Value II](/problems/closest-bst-value-ii) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/closest_bst_value_ii/solution.py) |
  | 295 | [Find Median from Data Stream](/problems/find-median-from-data-stream) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/find_median_from_data_stream/solution.py) |
  | 332 | [Reconstruct Itinerary](/problems/reconstruct-itinerary) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/reconstruct_itinerary/solution.py) |
  | 347 | [Top K Frequent Elements](/problems/top-k-frequent-elements) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/top_k_frequent_elements/solution.py) |
  | 355 | [Design Twitter](/problems/design-twitter) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/design_twitter/solution.py) |
  | 358 | [Rearrange String k Distance Apart](/problems/rearrange-string-k-distance-apart) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/rearrange_string_k_distance_apart/solution.py) |
  | 373 | [Find K Pairs with Smallest Sums](/problems/find-k-pairs-with-smallest-sums) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/find_k_pairs_with_smallest_sums/solution.py) |
  | 378 | [Kth Smallest Element in a Sorted Matrix](/problems/kth-smallest-element-in-a-sorted-matrix) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/kth_smallest_element_in_a_sorted_matrix/solution.py) |
  | 407 | [Trapping Rain Water II](/problems/trapping-rain-water-ii) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/trapping_rain_water_ii/solution.py) |
  | 420 | [Strong Password Checker](/problems/strong-password-checker) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/strong_password_checker/solution.py) |
  | 451 | [Sort Characters By Frequency](/problems/sort-characters-by-frequency) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/sort_characters_by_frequency/solution.py) |
  | 480 | [Sliding Window Median](/problems/sliding-window-median) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/sliding_window_median/solution.py) |
  | 499 | [The Maze III](/problems/the-maze-iii) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/the_maze_iii/solution.py) |
  | 502 | [IPO](/problems/ipo) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/ipo/solution.py) |
  | 505 | [The Maze II](/problems/the-maze-ii) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/the_maze_ii/solution.py) |
  | 506 | [Relative Ranks](/problems/relative-ranks) | Easy | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/relative_ranks/solution.py) |
  | 621 | [Task Scheduler](/problems/task-scheduler) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/task_scheduler/solution.py) |
  | 630 | [Course Schedule III](/problems/course-schedule-iii) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/course_schedule_iii/solution.py) |
  | 642 | [Design Search Autocomplete System](/problems/design-search-autocomplete-system) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/design_search_autocomplete_system/solution.py) |
  | 658 | [Find K Closest Elements](/problems/find-k-closest-elements) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/find_k_closest_elements/solution.py) |
  | 659 | [Split Array into Consecutive Subsequences](/problems/split-array-into-consecutive-subsequences) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/split_array_into_consecutive_subsequences/solution.py) |
  | 675 | [Cut Off Trees for Golf Event](/problems/cut-off-trees-for-golf-event) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/cut_off_trees_for_golf_event/solution.py) |
  | 683 | [K Empty Slots](/problems/k-empty-slots) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/k_empty_slots/solution.py) |
  | 692 | [Top K Frequent Words](/problems/top-k-frequent-words) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/top_k_frequent_words/solution.py) |
  | 703 | [Kth Largest Element in a Stream](/problems/kth-largest-element-in-a-stream) | Easy | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/kth_largest_element_in_a_stream/solution.py) |
  | 743 | [Network Delay Time](/problems/network-delay-time) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/network_delay_time/solution.py) |
  | 759 | [Employee Free Time](/problems/employee-free-time) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/employee_free_time/solution.py) |
  | 767 | [Reorganize String](/problems/reorganize-string) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/reorganize_string/solution.py) |
  | 778 | [Swim in Rising Water](/problems/swim-in-rising-water) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/swim_in_rising_water/solution.py) |
  | 786 | [K-th Smallest Prime Fraction](/problems/k-th-smallest-prime-fraction) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/k_th_smallest_prime_fraction/solution.py) |
  | 787 | [Cheapest Flights Within K Stops](/problems/cheapest-flights-within-k-stops) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/cheapest_flights_within_k_stops/solution.py) |
  | 855 | [Exam Room](/problems/exam-room) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/exam_room/solution.py) |
  | 857 | [Minimum Cost to Hire K Workers](/problems/minimum-cost-to-hire-k-workers) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/minimum_cost_to_hire_k_workers/solution.py) |
  | 862 | [Shortest Subarray with Sum at Least K](/problems/shortest-subarray-with-sum-at-least-k) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/shortest_subarray_with_sum_at_least_k/solution.py) |
  | 871 | [Minimum Number of Refueling Stops](/problems/minimum-number-of-refueling-stops) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/minimum_number_of_refueling_stops/solution.py) |
  | 882 | [Reachable Nodes In Subdivided Graph](/problems/reachable-nodes-in-subdivided-graph) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/reachable_nodes_in_subdivided_graph/solution.py) |
  | 912 | [Sort an Array](/problems/sort-an-array) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/sort_an_array/solution.py) |
  | 973 | [K Closest Points to Origin](/problems/k-closest-points-to-origin) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/k_closest_points_to_origin/solution.py) |
  | 1046 | [Last Stone Weight](/problems/last-stone-weight) | Easy | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/last_stone_weight/solution.py) |
  | 1057 | [Campus Bikes](/problems/campus-bikes) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/campus_bikes/solution.py) |
  | 1086 | [High Five](/problems/high-five) | Easy | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/high_five/solution.py) |
  | 1102 | [Path With Maximum Minimum Value](/problems/path-with-maximum-minimum-value) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/path_with_maximum_minimum_value/solution.py) |
  | 1135 | [Connecting Cities With Minimum Cost](/problems/connecting-cities-with-minimum-cost) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/connecting_cities_with_minimum_cost/solution.py) |
  | 1167 | [Minimum Cost to Connect Sticks](/problems/minimum-cost-to-connect-sticks) | Easy | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/minimum_cost_to_connect_sticks/solution.py) |
  | 1168 | [Optimize Water Distribution in a Village](/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](/problems/maximum-number-of-ones) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/maximum_number_of_ones/solution.py) |
  | 1268 | [Search Suggestions System](/problems/search-suggestions-system) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/search_suggestions_system/solution.py) |
  | 1368 | [Minimum Cost to Make at Least One Valid Path in a Grid](/problems/minimum-cost-to-make-at-least-one-valid-path-in-a-grid) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/minimum_cost_to_make_at_least_one_valid_path_in_a_grid/solution.py) |
  | 1383 | [Maximum Performance of a Team](/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) |
  | 1405 | [Longest Happy String](/problems/longest-happy-string) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/longest_happy_string/solution.py) |
  | 1425 | [Constrained Subsequence Sum](/problems/constrained-subsequence-sum) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/constrained_subsequence_sum/solution.py) |
  | 1438 | [Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit](/problems/longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/longest_continuous_subarray_with_absolute_diff_less_than_or_equal_to_limit/solution.py) |
  | 1514 | [Path with Maximum Probability](/problems/path-with-maximum-probability) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/path_with_maximum_probability/solution.py) |
  | 1631 | [Path With Minimum Effort](/problems/path-with-minimum-effort) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/path_with_minimum_effort/solution.py) |
  | 1642 | [Furthest Building You Can Reach](/problems/furthest-building-you-can-reach) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/furthest_building_you_can_reach/solution.py) |
  | 1675 | [Minimize Deviation in Array](/problems/minimize-deviation-in-array) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/minimize_deviation_in_array/solution.py) |
  | 1834 | [Single-Threaded CPU](/problems/single-threaded-cpu) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/single_threaded_cpu/solution.py) |
  | 1845 | [Seat Reservation Manager](/problems/seat-reservation-manager) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/seat_reservation_manager/solution.py) |
  | 1851 | [Minimum Interval to Include Each Query](/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) |
  | 1882 | [Process Tasks Using Servers](/problems/process-tasks-using-servers) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/process_tasks_using_servers/solution.py) |
  | 1942 | [The Number of the Smallest Unoccupied Chair](/problems/smallest-unoccupied-chair) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/smallest_unoccupied_chair/solution.py) |
  | 1985 | [Find the Kth Largest Integer in the Array](/problems/kth-largest-number-in-array) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/kth_largest_number_in_array/solution.py) |
  | 2182 | [Construct String With Repeat Limit](/problems/construct-string-with-repeat-limit) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/construct_string_with_repeat_limit/solution.py) |
  | 2285 | [Maximum Total Importance of Roads](/problems/maximum-total-importance-of-roads) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/maximum_total_importance_of_roads/solution.py) |
  | 2290 | [Minimum Obstacle Removal to Reach Corner](/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) |
  | 2353 | [Design a Food Rating System](/problems/design-a-food-rating-system) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/design_a_food_rating_system/solution.py) |
  | 2402 | [Meeting Rooms III](/problems/meeting-rooms-iii) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/meeting_rooms_iii/solution.py) |
  | 2406 | [Divide Intervals Into Minimum Number of Groups](/problems/divide-intervals-into-minimum-number-of-groups) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/divide_intervals_into_minimum_number_of_groups/solution.py) |
  | 2503 | [Maximum Number of Points From Grid Queries](/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) |
  | 2530 | [Maximal Score After Applying K Operations](/problems/maximal-score-after-applying-k-operations) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/maximal_score_after_applying_k_operations/solution.py) |
  | 2542 | [Maximum Subsequence Score](/problems/maximum-subsequence-score) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/maximum_subsequence_score/solution.py) |
  | 2551 | [Put Marbles in Bags](/problems/put-marbles-in-bags) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/put_marbles_in_bags/solution.py) |
  | 2558 | [Take Gifts From the Richest Pile](/problems/take-gifts-from-the-richest-pile) | Easy | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/take_gifts_from_the_richest_pile/solution.py) |
  | 2577 | [Minimum Time to Visit a Cell In a Grid](/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) |
  | 2812 | [Find the Safest Path in a Grid](/problems/find-the-safest-path-in-a-grid) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/find_the_safest_path_in_a_grid/solution.py) |
  | 2940 | [Find Building Where Alice and Bob Can Meet](/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) |
  | 3264 | [Final Array State After K Multiplication Operations I](/problems/final-array-state-after-k-multiplication-operations-i) | Easy | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/final_array_state_after_k_multiplication_operations_i/solution.py) |
  | 3572 | [Maximize Y-Sum by Picking a Triplet of Distinct X-Values](/problems/maximize-ysum-by-picking-a-triplet-of-distinct-xvalues) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/maximize_ysum_by_picking_a_triplet_of_distinct_xvalues/solution.py) |
  | 3711 | [Maximum Transactions Without Negative Balance](/problems/maximum-transactions-without-negative-balance) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/maximum_transactions_without_negative_balance/solution.py) |
</div>


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