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

# Stack in Python with Tests

> All 101 Stack LeetCode problems with tested Python solutions.

Stack holds 101 problems (20 Easy, 56 Medium, 25 Hard).
Generate any of them into the current directory with `lcpy gen -n <number>`.

<div className="sd-catalog-table">
  | # | Problem | Difficulty | Solution |
  | - | - | - | - |
  | 20 | [Valid Parentheses](/problems/valid-parentheses) | Easy | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/valid_parentheses/solution.py) |
  | 32 | [Longest Valid Parentheses](/problems/longest-valid-parentheses) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/longest_valid_parentheses/solution.py) |
  | 42 | [Trapping Rain Water](/problems/trapping-rain-water) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/trapping_rain_water/solution.py) |
  | 71 | [Simplify Path](/problems/simplify-path) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/simplify_path/solution.py) |
  | 84 | [Largest Rectangle in Histogram](/problems/largest-rectangle-in-histogram) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/largest_rectangle_in_histogram/solution.py) |
  | 85 | [Maximal Rectangle](/problems/maximal-rectangle) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/maximal_rectangle/solution.py) |
  | 94 | [Binary Tree Inorder Traversal](/problems/binary-tree-inorder-traversal) | Easy | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/binary_tree_inorder_traversal/solution.py) |
  | 114 | [Flatten Binary Tree to Linked List](/problems/flatten-binary-tree-to-linked-list) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/flatten_binary_tree_to_linked_list/solution.py) |
  | 143 | [Reorder List](/problems/reorder-list) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/reorder_list/solution.py) |
  | 144 | [Binary Tree Preorder Traversal](/problems/binary-tree-preorder-traversal) | Easy | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/binary_tree_preorder_traversal/solution.py) |
  | 145 | [Binary Tree Postorder Traversal](/problems/binary-tree-postorder-traversal) | Easy | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/binary_tree_postorder_traversal/solution.py) |
  | 150 | [Evaluate Reverse Polish Notation](/problems/evaluate-reverse-polish-notation) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/evaluate_reverse_polish_notation/solution.py) |
  | 155 | [Min Stack](/problems/min-stack) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/min_stack/solution.py) |
  | 173 | [Binary Search Tree Iterator](/problems/binary-search-tree-iterator) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/binary_search_tree_iterator/solution.py) |
  | 224 | [Basic Calculator](/problems/basic-calculator) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/basic_calculator/solution.py) |
  | 225 | [Implement Stack using Queues](/problems/implement-stack-using-queues) | Easy | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/implement_stack_using_queues/solution.py) |
  | 227 | [Basic Calculator II](/problems/basic-calculator-ii) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/basic_calculator_ii/solution.py) |
  | 232 | [Implement Queue using Stacks](/problems/implement-queue-using-stacks) | Easy | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/implement_queue_using_stacks/solution.py) |
  | 234 | [Palindrome Linked List](/problems/palindrome-linked-list) | Easy | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/palindrome_linked_list/solution.py) |
  | 255 | [Verify Preorder Sequence in Binary Search Tree](/problems/verify-preorder-sequence-in-binary-search-tree) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/verify_preorder_sequence_in_binary_search_tree/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) |
  | 316 | [Remove Duplicate Letters](/problems/remove-duplicate-letters) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/remove_duplicate_letters/solution.py) |
  | 321 | [Create Maximum Number](/problems/create-maximum-number) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/create_maximum_number/solution.py) |
  | 331 | [Verify Preorder Serialization of a Binary Tree](/problems/verify-preorder-serialization-of-a-binary-tree) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/verify_preorder_serialization_of_a_binary_tree/solution.py) |
  | 341 | [Flatten Nested List Iterator](/problems/flatten-nested-list-iterator) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/flatten_nested_list_iterator/solution.py) |
  | 364 | [Nested List Weight Sum II](/problems/nested-list-weight-sum-ii) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/nested_list_weight_sum_ii/solution.py) |
  | 385 | [Mini Parser](/problems/mini-parser) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/mini_parser/solution.py) |
  | 388 | [Longest Absolute File Path](/problems/longest-absolute-file-path) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/longest_absolute_file_path/solution.py) |
  | 394 | [Decode String](/problems/decode-string) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/decode_string/solution.py) |
  | 402 | [Remove K Digits](/problems/remove-k-digits) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/remove_k_digits/solution.py) |
  | 426 | [Convert Binary Search Tree to Sorted Doubly Linked List](/problems/convert-binary-search-tree-to-sorted-doubly-linked-list) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/convert_binary_search_tree_to_sorted_doubly_linked_list/solution.py) |
  | 439 | [Ternary Expression Parser](/problems/ternary-expression-parser) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/ternary_expression_parser/solution.py) |
  | 445 | [Add Two Numbers II](/problems/add-two-numbers-ii) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/add_two_numbers_ii/solution.py) |
  | 456 | [132 Pattern](/problems/pattern-132) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/pattern_132/solution.py) |
  | 484 | [Find Permutation](/problems/find-permutation) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/find_permutation/solution.py) |
  | 488 | [Zuma Game](/problems/zuma-game) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/zuma_game/solution.py) |
  | 496 | [Next Greater Element I](/problems/next-greater-element-i) | Easy | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/next_greater_element_i/solution.py) |
  | 503 | [Next Greater Element II](/problems/next-greater-element-ii) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/next_greater_element_ii/solution.py) |
  | 536 | [Construct Binary Tree from String](/problems/construct-binary-tree-from-string) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/construct_binary_tree_from_string/solution.py) |
  | 581 | [Shortest Unsorted Continuous Subarray](/problems/shortest-unsorted-continuous-subarray) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/shortest_unsorted_continuous_subarray/solution.py) |
  | 589 | [N-ary Tree Preorder Traversal](/problems/n-ary-tree-preorder-traversal) | Easy | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/n_ary_tree_preorder_traversal/solution.py) |
  | 590 | [N-ary Tree Postorder Traversal](/problems/n-ary-tree-postorder-traversal) | Easy | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/n_ary_tree_postorder_traversal/solution.py) |
  | 591 | [Tag Validator](/problems/tag-validator) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/tag_validator/solution.py) |
  | 636 | [Exclusive Time of Functions](/problems/exclusive-time-of-functions) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/exclusive_time_of_functions/solution.py) |
  | 654 | [Maximum Binary Tree](/problems/maximum-binary-tree) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/maximum_binary_tree/solution.py) |
  | 678 | [Valid Parenthesis String](/problems/valid-parenthesis-string) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/valid_parenthesis_string/solution.py) |
  | 682 | [Baseball Game](/problems/baseball-game) | Easy | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/baseball_game/solution.py) |
  | 716 | [Max Stack](/problems/max-stack) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/max_stack/solution.py) |
  | 726 | [Number of Atoms](/problems/number-of-atoms) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/number_of_atoms/solution.py) |
  | 735 | [Asteroid Collision](/problems/asteroid-collision) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/asteroid_collision/solution.py) |
  | 736 | [Parse Lisp Expression](/problems/parse-lisp-expression) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/parse_lisp_expression/solution.py) |
  | 739 | [Daily Temperatures](/problems/daily-temperatures) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/daily_temperatures/solution.py) |
  | 768 | [Max Chunks To Make Sorted II](/problems/max-chunks-to-make-sorted-ii) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/max_chunks_to_make_sorted_ii/solution.py) |
  | 769 | [Max Chunks To Make Sorted](/problems/max-chunks-to-make-sorted) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/max_chunks_to_make_sorted/solution.py) |
  | 770 | [Basic Calculator IV](/problems/basic-calculator-iv) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/basic_calculator_iv/solution.py) |
  | 772 | [Basic Calculator III](/problems/basic-calculator-iii) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/basic_calculator_iii/solution.py) |
  | 844 | [Backspace String Compare](/problems/backspace-string-compare) | Easy | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/backspace_string_compare/solution.py) |
  | 853 | [Car Fleet](/problems/car-fleet) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/car_fleet/solution.py) |
  | 856 | [Score of Parentheses](/problems/score-of-parentheses) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/score_of_parentheses/solution.py) |
  | 880 | [Decoded String at Index](/problems/decoded-string-at-index) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/decoded_string_at_index/solution.py) |
  | 895 | [Maximum Frequency Stack](/problems/maximum-frequency-stack) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/maximum_frequency_stack/solution.py) |
  | 897 | [Increasing Order Search Tree](/problems/increasing-order-search-tree) | Easy | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/increasing_order_search_tree/solution.py) |
  | 901 | [Online Stock Span](/problems/online-stock-span) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/online_stock_span/solution.py) |
  | 907 | [Sum of Subarray Minimums](/problems/sum-of-subarray-minimums) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/sum_of_subarray_minimums/solution.py) |
  | 921 | [Minimum Add to Make Parentheses Valid](/problems/minimum-add-to-make-parentheses-valid) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/minimum_add_to_make_parentheses_valid/solution.py) |
  | 936 | [Stamping The Sequence](/problems/stamping-the-sequence) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/stamping_the_sequence/solution.py) |
  | 946 | [Validate Stack Sequences](/problems/validate-stack-sequences) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/validate_stack_sequences/solution.py) |
  | 962 | [Maximum Width Ramp](/problems/maximum-width-ramp) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/maximum_width_ramp/solution.py) |
  | 975 | [Odd Even Jump](/problems/odd-even-jumps) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/odd_even_jumps/solution.py) |
  | 1106 | [Parsing A Boolean Expression](/problems/parsing-a-boolean-expression) | Hard | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/parsing_a_boolean_expression/solution.py) |
  | 1190 | [Reverse Substrings Between Each Pair of Parentheses](/problems/reverse-substrings-between-each-pair-of-parentheses) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/reverse_substrings_between_each_pair_of_parentheses/solution.py) |
  | 1209 | [Remove All Adjacent Duplicates in String II](/problems/remove-all-adjacent-duplicates-in-string-ii) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/remove_all_adjacent_duplicates_in_string_ii/solution.py) |
  | 1214 | [Two Sum BSTs](/problems/two-sum-bsts) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/two_sum_bsts/solution.py) |
  | 1249 | [Minimum Remove to Make Valid Parentheses](/problems/minimum-remove-to-make-valid-parentheses) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/minimum_remove_to_make_valid_parentheses/solution.py) |
  | 1265 | [Print Immutable Linked List in Reverse](/problems/print-immutable-linked-list-in-reverse) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/print_immutable_linked_list_in_reverse/solution.py) |
  | 1472 | [Design Browser History](/problems/design-browser-history) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/design_browser_history/solution.py) |
  | 1475 | [Final Prices With a Special Discount in a Shop](/problems/final-prices-with-a-special-discount-in-a-shop) | Easy | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/final_prices_with_a_special_discount_in_a_shop/solution.py) |
  | 1526 | [Minimum Number of Increments on Subarrays to Form a Target Array](/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) |
  | 1544 | [Make The String Great](/problems/make-the-string-great) | Easy | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/make_the_string_great/solution.py) |
  | 1574 | [Shortest Subarray to be Removed to Make Array Sorted](/problems/shortest-subarray-to-be-removed-to-make-array-sorted) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/shortest_subarray_to_be_removed_to_make_array_sorted/solution.py) |
  | 1598 | [Crawler Log Folder](/problems/crawler-log-folder) | Easy | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/crawler_log_folder/solution.py) |
  | 1614 | [Maximum Nesting Depth of the Parentheses](/problems/maximum-nesting-depth-of-the-parentheses) | Easy | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/maximum_nesting_depth_of_the_parentheses/solution.py) |
  | 1653 | [Minimum Deletions to Make String Balanced](/problems/minimum-deletions-to-make-string-balanced) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/minimum_deletions_to_make_string_balanced/solution.py) |
  | 1700 | [Number of Students Unable to Eat Lunch](/problems/number-of-students-unable-to-eat-lunch) | Easy | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/number_of_students_unable_to_eat_lunch/solution.py) |
  | 1717 | [Maximum Score From Removing Substrings](/problems/maximum-score-from-removing-substrings) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/maximum_score_from_removing_substrings/solution.py) |
  | 1762 | [Buildings With an Ocean View](/problems/buildings-with-an-ocean-view) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/buildings_with_an_ocean_view/solution.py) |
  | 1793 | [Maximum Score of a Good Subarray](/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) |
  | 1856 | [Maximum Subarray Min-Product](/problems/maximum-subarray-min-product) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/maximum_subarray_min_product/solution.py) |
  | 1944 | [Number of Visible People in a Queue](/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) |
  | 1963 | [Minimum Number of Swaps to Make the String Balanced](/problems/minimum-number-of-swaps-to-make-the-string-balanced) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/minimum_number_of_swaps_to_make_the_string_balanced/solution.py) |
  | 1966 | [Binary Searchable Numbers in an Unsorted Array](/problems/binary-searchable-numbers-in-an-unsorted-array) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/binary_searchable_numbers_in_an_unsorted_array/solution.py) |
  | 2116 | [Check if a Parentheses String Can Be Valid](/problems/check-if-a-parentheses-string-can-be-valid) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/check_if_a_parentheses_string_can_be_valid/solution.py) |
  | 2130 | [Maximum Twin Sum of a Linked List](/problems/maximum-twin-sum-of-a-linked-list) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/maximum_twin_sum_of_a_linked_list/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) |
  | 2390 | [Removing Stars From a String](/problems/removing-stars-from-a-string) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/removing_stars_from_a_string/solution.py) |
  | 2487 | [Remove Nodes From Linked List](/problems/remove-nodes-from-linked-list) | Medium | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/remove_nodes_from_linked_list/solution.py) |
  | 2696 | [Minimum String Length After Removing Substrings](/problems/minimum-string-length-after-removing-substrings) | Easy | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/minimum_string_length_after_removing_substrings/solution.py) |
  | 2751 | [Robot Collisions](/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](/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) |
  | 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) |
  | 3174 | [Clear Digits](/problems/clear-digits) | Easy | [solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/clear_digits/solution.py) |
</div>


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