From 5c93771da5062ad8539b859c206bc9d252bbdcd7 Mon Sep 17 00:00:00 2001 From: Wisaroot Lertthaweedech Date: Sat, 4 Oct 2025 10:24:18 +0700 Subject: [PATCH 1/3] docs: update docs --- .../1-update-cookiecutter-test-template.md | 170 ++++++++++++++++++ 1 file changed, 170 insertions(+) create mode 100644 .cursor/.dev/1-update-cookiecutter-test-template.md diff --git a/.cursor/.dev/1-update-cookiecutter-test-template.md b/.cursor/.dev/1-update-cookiecutter-test-template.md new file mode 100644 index 0000000..f53a895 --- /dev/null +++ b/.cursor/.dev/1-update-cookiecutter-test-template.md @@ -0,0 +1,170 @@ +# Plan: Update CookieCutter Test Template to Use For Loop Instead of Parametrize + +## Overview + +Update the cookiecutter template for `test_solution.py` to use a for loop approach for test cases instead of the current `@pytest.mark.parametrize` decorator. This will make the test structure more explicit and easier to read. + +## Current State Analysis + +### Current Template Structure + +- Uses `@pytest.mark.parametrize` decorator with `method.parametrize` and `method.test_cases` +- Test cases are stored as a single string in JSON: `"[([1, 2, 3], [1, 2, 3], True), ...]"` +- Generated test method signature includes all parameters: `(self, p_list: list[int | None], q_list: list[int | None], expected: bool)` + +### Current JSON Structure + +```json +"_test_methods": { + "list": [ + { + "name": "test_is_same_tree", + "signature": "(self, p_list: list[int | None], q_list: list[int | None], expected: bool)", + "parametrize": "p_list, q_list, expected", + "test_cases": "[([1, 2, 3], [1, 2, 3], True), ([1, 2], [1, None, 2], False), ...]", + "body": "result = run_is_same_tree(Solution, p_list, q_list)\nassert_is_same_tree(result, expected)" + } + ] +} +``` + +## Target State + +### New Template Structure + +- Keep `@pytest.mark.parametrize` decorator +- Use a for loop to iterate through individual test cases from the list +- Test method signature remains the same +- Only change: `test_cases` becomes a list instead of a string + +### New JSON Structure + +```json +"_test_methods": { + "list": [ + { + "name": "test_is_same_tree", + "signature": "(self, p_list: list[int | None], q_list: list[int | None], expected: bool)", + "parametrize": "p_list, q_list, expected", + "test_cases": { + "list": [ + "([1, 2, 3], [1, 2, 3], True)", + "([1, 2], [1, None, 2], False)", + "([1, 2, 1], [1, 1, 2], False)" + ] + }, + "body": "result = run_is_same_tree(Solution, p_list, q_list)\nassert_is_same_tree(result, expected)" + } + ] +} +``` + +## Implementation Plan + +### Phase 1: Update CookieCutter Template + +1. **Update `test_solution.py` template** + - Change from `{{method.test_cases}}` to `{{method.test_cases.list | join(', ')}}` + - This follows the existing pattern used by other list fields in the template + - Template line 30: `@pytest.mark.parametrize("{{method.parametrize}}", [{{method.test_cases.list | join(', ')}}])` + +### Phase 2: Create JSON Migration Script + +1. **Create `migrate_test_cases.py` script** + - Parse existing JSON files in `leetcode_py/cli/resources/leetcode/json/problems/` + - Convert `test_cases` string to `{"list": ["test_case1", "test_case2", ...]}` format + - Keep all other fields exactly the same + - Update only the `test_cases` field structure + +### Phase 3: Update JSON Files + +1. **Run migration script on all existing problem JSON files** + - Process all 107 JSON files in the problems directory + - Create backup of original files + - Validate migrated JSON structure + +### Phase 4: Update Template Generation Logic + +1. **Modify cookiecutter generation code** + - Update any code that generates the `test_cases` field to output JSON arrays instead of strings + - Ensure new list format is used when creating new problems + - Keep all other generation logic the same + +### Phase 5: Testing and Validation + +1. **Test generated templates** + - Generate a test problem using updated template + - Verify test cases run correctly with parametrize approach + - Ensure JSON list format works with pytest parametrize + +2. **Comprehensive validation with all problems** + - Copy additional LeetCode problems to `.cache/leetcode` (if not already present) + - Regenerate ALL problems from new design using updated template + - Copy existing solutions from cache to regenerated problems + - Run tests on all regenerated problems to ensure they still pass + - Verify no regressions in test functionality + - Document any issues found and fix them + +### Phase 6: Update Documentation + +1. **Update problem creation documentation** + - Update `.cursor/commands/problem-creation.md` to reflect new JSON structure + - Change `test_cases` format from string to `{"list": [...]}` in examples + - Update template examples to show new format + - Add note about migration for existing problems +2. **Update any other related documentation** + - Check for other docs that reference `test_cases` format + - Update examples in README or other guides if needed + +## Benefits of New Approach + +1. **Cleaner JSON Structure**: Test cases as `{"list": [...]}` object instead of single string +2. **Better Maintainability**: Easier to edit individual test cases in JSON files +3. **No Parsing Issues**: Avoids tuple conversion and complex JSON parsing +4. **Consistency**: Aligns with other JSON list fields in the structure +5. **Template Consistency**: Uses same pattern as other list fields (`| join(', ')`) + +## Files to Modify + +### Template Files + +- `leetcode_py/cli/resources/leetcode/{{cookiecutter.problem_name}}/test_solution.py` + +### Migration Script + +- `migrate_test_cases.py` (new file) + +### JSON Files + +- All files in `leetcode_py/cli/resources/leetcode/json/problems/` (107 files) + +### Generation Code + +- Any code that creates the `test_cases` field (to be identified) + +## Implementation Steps + +1. ✅ Create this plan document +2. 🔄 Update cookiecutter template +3. 🔄 Create migration script +4. 🔄 Run migration on all JSON files +5. 🔄 Test updated template generation +6. 🔄 Validate all tests still work +7. 🔄 Update documentation (separate step - do not combine with implementation) + +## Risk Mitigation + +1. **Backup Strategy**: Create backups of all JSON files before migration +2. **Incremental Testing**: Test migration on a few files first +3. **Rollback Plan**: Keep original template and migration script for rollback +4. **Validation**: Ensure all existing tests still pass after migration + +## Success Criteria + +1. All existing JSON files successfully migrated to new list format +2. Generated test templates work with JSON array format for test_cases +3. All existing tests continue to pass with parametrize approach +4. JSON structure is cleaner and more maintainable +5. Template generation works correctly for new problems +6. **All regenerated problems pass their tests** (comprehensive validation) +7. No regressions in test functionality across the entire problem set From cb972f52a99fe9ec38fc9b7997a4d9c9c398d171 Mon Sep 17 00:00:00 2001 From: Wisaroot Lertthaweedech Date: Sat, 4 Oct 2025 10:58:22 +0700 Subject: [PATCH 2/3] feat: imporve test cases in cookiecutter template --- .../1-update-cookiecutter-test-template.md | 26 +++--- .../json/problems/accounts_merge.json | 29 ++++++- .../leetcode/json/problems/add_binary.json | 36 +++++++-- .../json/problems/alien_dictionary.json | 39 ++++++++- .../json/problems/balanced_binary_tree.json | 36 ++++++++- .../json/problems/basic_calculator.json | 53 ++++++++++-- .../best_time_to_buy_and_sell_stock.json | 32 +++++++- .../leetcode/json/problems/binary_search.json | 30 ++++++- .../binary_tree_level_order_traversal.json | 38 +++++++-- .../problems/binary_tree_right_side_view.json | 39 +++++++-- .../json/problems/climbing_stairs.json | 34 +++++++- .../leetcode/json/problems/clone_graph.json | 80 ++++++++++++++++++- .../leetcode/json/problems/coin_change.json | 40 ++++++++-- .../json/problems/combination_sum.json | 33 +++++++- ...e_from_preorder_and_inorder_traversal.json | 37 ++++++++- .../problems/container_with_most_water.json | 33 +++++++- .../json/problems/contains_duplicate.json | 33 +++++++- .../json/problems/contiguous_array.json | 34 +++++++- .../json/problems/course_schedule.json | 29 ++++++- .../json/problems/course_schedule_ii.json | 47 ++++++++--- .../json/problems/daily_temperatures.json | 60 ++++++++++++-- .../leetcode/json/problems/decode_string.json | 44 ++++++++-- .../leetcode/json/problems/decode_ways.json | 30 ++++++- ...n_add_and_search_words_data_structure.json | 32 +++++--- .../design_in_memory_file_system.json | 21 ++++- .../json/problems/diagonal_traverse.json | 33 +++++++- .../problems/diameter_of_binary_tree.json | 33 +++++++- .../evaluate_reverse_polish_notation.json | 30 ++++++- .../find_all_anagrams_in_a_string.json | 29 ++++++- .../problems/find_k_closest_elements.json | 43 ++++++++-- .../find_median_from_data_stream.json | 25 +++++- .../problems/find_the_duplicate_number.json | 47 +++++++++-- .../json/problems/first_bad_version.json | 36 ++++++++- .../leetcode/json/problems/flood_fill.json | 29 ++++++- .../leetcode/json/problems/gas_station.json | 25 +++++- .../json/problems/group_anagrams.json | 50 ++++++++---- .../leetcode/json/problems/house_robber.json | 42 +++++++--- .../implement_queue_using_stacks.json | 25 +++++- .../problems/implement_trie_prefix_tree.json | 25 +++++- .../json/problems/insert_interval.json | 31 ++++++- .../json/problems/invert_binary_tree.json | 44 ++++++++-- .../leetcode/json/problems/jump_game.json | 32 +++++++- .../problems/k_closest_points_to_origin.json | 31 ++++++- .../kth_smallest_element_in_a_bst.json | 29 ++++++- .../largest_rectangle_in_histogram.json | 33 +++++++- ...letter_combinations_of_a_phone_number.json | 37 +++++++-- .../json/problems/linked_list_cycle.json | 32 +++++++- .../longest_consecutive_sequence.json | 40 ++++++++-- .../longest_increasing_subsequence.json | 48 ++++++++--- .../json/problems/longest_palindrome.json | 30 ++++++- .../longest_palindromic_substring.json | 33 +++++++- ...ubstring_without_repeating_characters.json | 30 ++++++- ...mmon_ancestor_of_a_binary_search_tree.json | 33 +++++++- ...west_common_ancestor_of_a_binary_tree.json | 33 +++++++- .../leetcode/json/problems/lru_cache.json | 25 +++++- .../json/problems/majority_element.json | 42 ++++++++-- .../maximum_depth_of_binary_tree.json | 36 ++++++++- .../problems/maximum_product_subarray.json | 42 +++++++--- .../maximum_profit_in_job_scheduling.json | 29 ++++++- .../json/problems/maximum_subarray.json | 32 +++++++- .../maximum_width_of_binary_tree.json | 33 +++++++- .../json/problems/merge_intervals.json | 29 ++++++- .../json/problems/merge_k_sorted_lists.json | 40 ++++++++-- .../json/problems/merge_two_sorted_lists.json | 39 +++++++-- .../problems/middle_of_the_linked_list.json | 31 ++++++- .../leetcode/json/problems/min_stack.json | 25 +++++- .../json/problems/minimum_height_trees.json | 29 ++++++- .../problems/minimum_window_substring.json | 28 ++++++- .../json/problems/next_permutation.json | 54 +++++++++---- .../json/problems/number_of_islands.json | 31 ++++++- .../json/problems/odd_even_linked_list.json | 33 +++++++- .../problems/pacific_atlantic_water_flow.json | 39 ++++++--- .../problems/partition_equal_subset_sum.json | 32 +++++++- .../leetcode/json/problems/path_sum_ii.json | 41 +++++++--- .../leetcode/json/problems/permutations.json | 37 +++++++-- .../product_of_array_except_self.json | 40 ++++++++-- .../leetcode/json/problems/ransom_note.json | 40 ++++++++-- .../remove_nth_node_from_end_of_list.json | 43 ++++++++-- .../json/problems/reverse_linked_list.json | 36 ++++++++- .../json/problems/reverse_linked_list_ii.json | 33 +++++++- .../leetcode/json/problems/rotate_array.json | 32 +++++++- .../leetcode/json/problems/rotate_image.json | 29 ++++++- .../json/problems/rotting_oranges.json | 28 ++++++- .../leetcode/json/problems/same_tree.json | 28 ++++++- .../search_in_rotated_sorted_array.json | 44 ++++++++-- ...serialize_and_deserialize_binary_tree.json | 32 +++++++- .../json/problems/set_matrix_zeroes.json | 32 +++++++- .../leetcode/json/problems/sort_colors.json | 40 ++++++++-- .../leetcode/json/problems/spiral_matrix.json | 31 ++++++- .../json/problems/string_to_integer_atoi.json | 30 ++++++- .../leetcode/json/problems/subsets.json | 33 +++++++- .../json/problems/swap_nodes_in_pairs.json | 49 ++++++++---- .../json/problems/task_scheduler.json | 29 ++++++- .../leetcode/json/problems/three_sum.json | 29 ++++++- .../problems/time_based_key_value_store.json | 25 +++++- .../json/problems/top_k_frequent_words.json | 35 +++++++- .../json/problems/trapping_rain_water.json | 36 ++++++++- .../leetcode/json/problems/two_sum.json | 43 ++++++++-- .../leetcode/json/problems/unique_paths.json | 32 +++++++- .../leetcode/json/problems/valid_anagram.json | 43 ++++++++-- .../json/problems/valid_palindrome.json | 33 +++++++- .../json/problems/valid_parentheses.json | 57 +++++++++++-- .../leetcode/json/problems/valid_sudoku.json | 43 +++++++--- .../problems/validate_binary_search_tree.json | 29 ++++++- .../leetcode/json/problems/word_break.json | 32 +++++++- .../leetcode/json/problems/word_ladder.json | 32 +++++++- .../leetcode/json/problems/word_search.json | 29 ++++++- .../json/problems/zero_one_matrix.json | 30 ++++++- .../test_solution.py | 2 +- leetcode_py/tools/check_test_cases.py | 20 +---- 110 files changed, 3297 insertions(+), 542 deletions(-) diff --git a/.cursor/.dev/1-update-cookiecutter-test-template.md b/.cursor/.dev/1-update-cookiecutter-test-template.md index f53a895..2c57cc4 100644 --- a/.cursor/.dev/1-update-cookiecutter-test-template.md +++ b/.cursor/.dev/1-update-cookiecutter-test-template.md @@ -67,6 +67,7 @@ Update the cookiecutter template for `test_solution.py` to use a for loop approa - Change from `{{method.test_cases}}` to `{{method.test_cases.list | join(', ')}}` - This follows the existing pattern used by other list fields in the template - Template line 30: `@pytest.mark.parametrize("{{method.parametrize}}", [{{method.test_cases.list | join(', ')}}])` + - **✅ Validated:** Correctly follows existing "list" pattern used by `_tags`, `_readme_examples`, etc. ### Phase 2: Create JSON Migration Script @@ -83,14 +84,7 @@ Update the cookiecutter template for `test_solution.py` to use a for loop approa - Create backup of original files - Validate migrated JSON structure -### Phase 4: Update Template Generation Logic - -1. **Modify cookiecutter generation code** - - Update any code that generates the `test_cases` field to output JSON arrays instead of strings - - Ensure new list format is used when creating new problems - - Keep all other generation logic the same - -### Phase 5: Testing and Validation +### Phase 4: Testing and Validation 1. **Test generated templates** - Generate a test problem using updated template @@ -105,7 +99,7 @@ Update the cookiecutter template for `test_solution.py` to use a for loop approa - Verify no regressions in test functionality - Document any issues found and fix them -### Phase 6: Update Documentation +### Phase 5: Update Documentation 1. **Update problem creation documentation** - Update `.cursor/commands/problem-creation.md` to reflect new JSON structure @@ -140,16 +134,18 @@ Update the cookiecutter template for `test_solution.py` to use a for loop approa ### Generation Code -- Any code that creates the `test_cases` field (to be identified) +- **No changes needed** - The `test_cases` field is created manually, not by automated code +- The existing "list" pattern is already established and working correctly +- Phase 4 removed after investigation showed no automated generation code exists ## Implementation Steps 1. ✅ Create this plan document -2. 🔄 Update cookiecutter template -3. 🔄 Create migration script -4. 🔄 Run migration on all JSON files -5. 🔄 Test updated template generation -6. 🔄 Validate all tests still work +2. ✅ Update cookiecutter template +3. ✅ Create migration script +4. ✅ Run migration on all JSON files +5. ✅ Test updated template generation +6. ✅ Validate all tests still work 7. 🔄 Update documentation (separate step - do not combine with implementation) ## Risk Mitigation diff --git a/leetcode_py/cli/resources/leetcode/json/problems/accounts_merge.json b/leetcode_py/cli/resources/leetcode/json/problems/accounts_merge.json index 08b14e0..e15421a 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/accounts_merge.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/accounts_merge.json @@ -5,7 +5,9 @@ "problem_title": "Accounts Merge", "difficulty": "Medium", "topics": "Array, Hash Table, String, Depth-First Search, Breadth-First Search, Union Find, Sorting", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "Given a list of `accounts` where each element `accounts[i]` is a list of strings, where the first element `accounts[i][0]` is a name, and the rest of the elements are emails representing emails of the account.\n\nNow, we would like to merge these accounts. Two accounts definitely belong to the same person if there is some common email to both accounts. Note that even if two accounts have the same name, they may belong to different people as people could have the same name. A person can have any number of accounts initially, but all of their accounts definitely have the same name.\n\nAfter merging the accounts, return the accounts in the following format: the first element of each account is the name, and the rest of the elements are emails in sorted order. The accounts themselves can be returned in any order.", "_readme_examples": { "list": [ @@ -44,7 +46,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -52,7 +60,22 @@ "name": "test_accounts_merge", "signature": "(self, accounts: list[list[str]], expected: list[list[str]])", "parametrize": "accounts, expected", - "test_cases": "[([['John', 'johnsmith@mail.com', 'john_newyork@mail.com'], ['John', 'johnsmith@mail.com', 'john00@mail.com'], ['Mary', 'mary@mail.com'], ['John', 'johnnybravo@mail.com']], [['John', 'john00@mail.com', 'john_newyork@mail.com', 'johnsmith@mail.com'], ['Mary', 'mary@mail.com'], ['John', 'johnnybravo@mail.com']]), ([['Gabe', 'Gabe0@m.co', 'Gabe3@m.co', 'Gabe1@m.co'], ['Kevin', 'Kevin3@m.co', 'Kevin5@m.co', 'Kevin0@m.co'], ['Ethan', 'Ethan5@m.co', 'Ethan4@m.co', 'Ethan0@m.co'], ['Hanzo', 'Hanzo3@m.co', 'Hanzo1@m.co', 'Hanzo0@m.co'], ['Fern', 'Fern5@m.co', 'Fern1@m.co', 'Fern0@m.co']], [['Ethan', 'Ethan0@m.co', 'Ethan4@m.co', 'Ethan5@m.co'], ['Gabe', 'Gabe0@m.co', 'Gabe1@m.co', 'Gabe3@m.co'], ['Hanzo', 'Hanzo0@m.co', 'Hanzo1@m.co', 'Hanzo3@m.co'], ['Kevin', 'Kevin0@m.co', 'Kevin3@m.co', 'Kevin5@m.co'], ['Fern', 'Fern0@m.co', 'Fern1@m.co', 'Fern5@m.co']]), ([['Alice', 'alice@mail.com']], [['Alice', 'alice@mail.com']]), ([['Bob', 'bob1@mail.com'], ['Bob', 'bob2@mail.com']], [['Bob', 'bob1@mail.com'], ['Bob', 'bob2@mail.com']]), ([['Alice', 'alice@mail.com', 'alice2@mail.com'], ['Alice', 'alice2@mail.com', 'alice3@mail.com']], [['Alice', 'alice2@mail.com', 'alice3@mail.com', 'alice@mail.com']]), ([['A', 'a@mail.com', 'b@mail.com'], ['B', 'b@mail.com', 'c@mail.com'], ['C', 'c@mail.com', 'd@mail.com']], [['A', 'a@mail.com', 'b@mail.com', 'c@mail.com', 'd@mail.com']]), ([['David', 'david@mail.com'], ['David', 'david@mail.com']], [['David', 'david@mail.com']]), ([['Alex', 'alex1@mail.com'], ['Bob', 'bob1@mail.com'], ['Charlie', 'charlie1@mail.com']], [['Alex', 'alex1@mail.com'], ['Bob', 'bob1@mail.com'], ['Charlie', 'charlie1@mail.com']]), ([['John', 'john1@mail.com', 'john2@mail.com'], ['John', 'john3@mail.com'], ['Jane', 'jane1@mail.com']], [['John', 'john1@mail.com', 'john2@mail.com'], ['John', 'john3@mail.com'], ['Jane', 'jane1@mail.com']]), ([['User', 'user@mail.com', 'user1@mail.com'], ['User', 'user2@mail.com', 'user@mail.com'], ['User', 'user3@mail.com', 'user1@mail.com']], [['User', 'user1@mail.com', 'user2@mail.com', 'user3@mail.com', 'user@mail.com']]), ([['Test', 'test1@mail.com'], ['Test', 'test2@mail.com'], ['Test', 'test1@mail.com', 'test3@mail.com']], [['Test', 'test2@mail.com'], ['Test', 'test1@mail.com', 'test3@mail.com']]), ([['Name', 'a@mail.com', 'b@mail.com', 'c@mail.com'], ['Name', 'd@mail.com', 'e@mail.com'], ['Name', 'c@mail.com', 'f@mail.com']], [['Name', 'd@mail.com', 'e@mail.com'], ['Name', 'a@mail.com', 'b@mail.com', 'c@mail.com', 'f@mail.com']])]", + "test_cases": { + "list": [ + "([['John', 'johnsmith@mail.com', 'john_newyork@mail.com'], ['John', 'johnsmith@mail.com', 'john00@mail.com'], ['Mary', 'mary@mail.com'], ['John', 'johnnybravo@mail.com']], [['John', 'john00@mail.com', 'john_newyork@mail.com', 'johnsmith@mail.com'], ['Mary', 'mary@mail.com'], ['John', 'johnnybravo@mail.com']])", + "([['Gabe', 'Gabe0@m.co', 'Gabe3@m.co', 'Gabe1@m.co'], ['Kevin', 'Kevin3@m.co', 'Kevin5@m.co', 'Kevin0@m.co'], ['Ethan', 'Ethan5@m.co', 'Ethan4@m.co', 'Ethan0@m.co'], ['Hanzo', 'Hanzo3@m.co', 'Hanzo1@m.co', 'Hanzo0@m.co'], ['Fern', 'Fern5@m.co', 'Fern1@m.co', 'Fern0@m.co']], [['Ethan', 'Ethan0@m.co', 'Ethan4@m.co', 'Ethan5@m.co'], ['Gabe', 'Gabe0@m.co', 'Gabe1@m.co', 'Gabe3@m.co'], ['Hanzo', 'Hanzo0@m.co', 'Hanzo1@m.co', 'Hanzo3@m.co'], ['Kevin', 'Kevin0@m.co', 'Kevin3@m.co', 'Kevin5@m.co'], ['Fern', 'Fern0@m.co', 'Fern1@m.co', 'Fern5@m.co']])", + "([['Alice', 'alice@mail.com']], [['Alice', 'alice@mail.com']])", + "([['Bob', 'bob1@mail.com'], ['Bob', 'bob2@mail.com']], [['Bob', 'bob1@mail.com'], ['Bob', 'bob2@mail.com']])", + "([['Alice', 'alice@mail.com', 'alice2@mail.com'], ['Alice', 'alice2@mail.com', 'alice3@mail.com']], [['Alice', 'alice2@mail.com', 'alice3@mail.com', 'alice@mail.com']])", + "([['A', 'a@mail.com', 'b@mail.com'], ['B', 'b@mail.com', 'c@mail.com'], ['C', 'c@mail.com', 'd@mail.com']], [['A', 'a@mail.com', 'b@mail.com', 'c@mail.com', 'd@mail.com']])", + "([['David', 'david@mail.com'], ['David', 'david@mail.com']], [['David', 'david@mail.com']])", + "([['Alex', 'alex1@mail.com'], ['Bob', 'bob1@mail.com'], ['Charlie', 'charlie1@mail.com']], [['Alex', 'alex1@mail.com'], ['Bob', 'bob1@mail.com'], ['Charlie', 'charlie1@mail.com']])", + "([['John', 'john1@mail.com', 'john2@mail.com'], ['John', 'john3@mail.com'], ['Jane', 'jane1@mail.com']], [['John', 'john1@mail.com', 'john2@mail.com'], ['John', 'john3@mail.com'], ['Jane', 'jane1@mail.com']])", + "([['User', 'user@mail.com', 'user1@mail.com'], ['User', 'user2@mail.com', 'user@mail.com'], ['User', 'user3@mail.com', 'user1@mail.com']], [['User', 'user1@mail.com', 'user2@mail.com', 'user3@mail.com', 'user@mail.com']])", + "([['Test', 'test1@mail.com'], ['Test', 'test2@mail.com'], ['Test', 'test1@mail.com', 'test3@mail.com']], [['Test', 'test2@mail.com'], ['Test', 'test1@mail.com', 'test3@mail.com']])", + "([['Name', 'a@mail.com', 'b@mail.com', 'c@mail.com'], ['Name', 'd@mail.com', 'e@mail.com'], ['Name', 'c@mail.com', 'f@mail.com']], [['Name', 'd@mail.com', 'e@mail.com'], ['Name', 'a@mail.com', 'b@mail.com', 'c@mail.com', 'f@mail.com']])" + ] + }, "body": " result = run_accounts_merge(Solution, accounts)\n assert_accounts_merge(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/add_binary.json b/leetcode_py/cli/resources/leetcode/json/problems/add_binary.json index 34caf68..f0b21c3 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/add_binary.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/add_binary.json @@ -5,12 +5,18 @@ "problem_title": "Add Binary", "difficulty": "Easy", "topics": "Math, String, Bit Manipulation, Simulation", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "Given two binary strings `a` and `b`, return *their sum as a binary string*.", "_readme_examples": { "list": [ - { "content": "```\nInput: a = \"11\", b = \"1\"\nOutput: \"100\"\n```" }, - { "content": "```\nInput: a = \"1010\", b = \"1011\"\nOutput: \"10101\"\n```" } + { + "content": "```\nInput: a = \"11\", b = \"1\"\nOutput: \"100\"\n```" + }, + { + "content": "```\nInput: a = \"1010\", b = \"1011\"\nOutput: \"10101\"\n```" + } ] }, "readme_constraints": "- `1 <= a.length, b.length <= 10^4`\n- `a` and `b` consist only of `'0'` or `'1'` characters.\n- Each string does not contain leading zeros except for the zero itself.", @@ -40,7 +46,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -48,7 +60,21 @@ "name": "test_add_binary", "signature": "(self, a: str, b: str, expected: str)", "parametrize": "a, b, expected", - "test_cases": "[('11', '1', '100'), ('1010', '1011', '10101'), ('0', '0', '0'), ('1', '1', '10'), ('1111', '1111', '11110'), ('1', '0', '1'), ('0', '1', '1'), ('1', '111', '1000'), ('111', '1', '1000'), ('1010', '1', '1011'), ('1111', '1', '10000')]", + "test_cases": { + "list": [ + "('11', '1', '100')", + "('1010', '1011', '10101')", + "('0', '0', '0')", + "('1', '1', '10')", + "('1111', '1111', '11110')", + "('1', '0', '1')", + "('0', '1', '1')", + "('1', '111', '1000')", + "('111', '1', '1000')", + "('1010', '1', '1011')", + "('1111', '1', '10000')" + ] + }, "body": " result = run_add_binary(Solution, a, b)\n assert_add_binary(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/alien_dictionary.json b/leetcode_py/cli/resources/leetcode/json/problems/alien_dictionary.json index 2850dea..46a0756 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/alien_dictionary.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/alien_dictionary.json @@ -5,14 +5,18 @@ "problem_title": "Alien Dictionary", "difficulty": "Hard", "topics": "Array, String, Depth-First Search, Breadth-First Search, Graph, Topological Sort", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "There is a new alien language that uses the English alphabet. However, the order among the letters is unknown to you.\n\nYou are given a list of strings `words` from the alien language's dictionary, where the strings in `words` are **sorted lexicographically** by the rules of this new language.\n\nReturn *a string of the unique letters in the new alien language sorted in **lexicographically increasing order** by the new language's rules. If there is no solution, return* `\"\"`*. If there are multiple solutions, return **any of them***.", "_readme_examples": { "list": [ { "content": "```\nInput: words = [\"wrt\",\"wrf\",\"er\",\"ett\",\"rftt\"]\nOutput: \"wertf\"\n```" }, - { "content": "```\nInput: words = [\"z\",\"x\"]\nOutput: \"zx\"\n```" }, + { + "content": "```\nInput: words = [\"z\",\"x\"]\nOutput: \"zx\"\n```" + }, { "content": "```\nInput: words = [\"z\",\"x\",\"z\"]\nOutput: \"\"\nExplanation: The order is invalid, so return \"\".\n```" } @@ -45,7 +49,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -53,7 +63,28 @@ "name": "test_alien_order", "signature": "(self, words: list[str], expected: str)", "parametrize": "words, expected", - "test_cases": "[(['wrt', 'wrf', 'er', 'ett', 'rftt'], 'wertf'), (['z', 'x'], 'zx'), (['z', 'x', 'z'], ''), (['z', 'z'], 'z'), (['abc', 'ab'], ''), (['ab', 'adc'], 'abdc'), (['ac', 'ab', 'zc', 'zb'], 'acbz'), (['z'], 'z'), (['za', 'zb', 'ca', 'cb'], 'zcab'), (['zy', 'zx'], 'zyx'), (['a', 'b', 'ca', 'cc'], 'abc'), (['abc', 'bcd', 'cde'], 'abcde'), (['a', 'aa'], 'a'), (['ab', 'abc'], 'abc'), (['abc', 'ab'], ''), (['a', 'b', 'c', 'd'], 'abcd'), (['d', 'c', 'b', 'a'], 'dcba'), (['ac', 'ab', 'b'], 'acb')]", + "test_cases": { + "list": [ + "(['wrt', 'wrf', 'er', 'ett', 'rftt'], 'wertf')", + "(['z', 'x'], 'zx')", + "(['z', 'x', 'z'], '')", + "(['z', 'z'], 'z')", + "(['abc', 'ab'], '')", + "(['ab', 'adc'], 'abdc')", + "(['ac', 'ab', 'zc', 'zb'], 'acbz')", + "(['z'], 'z')", + "(['za', 'zb', 'ca', 'cb'], 'zcab')", + "(['zy', 'zx'], 'zyx')", + "(['a', 'b', 'ca', 'cc'], 'abc')", + "(['abc', 'bcd', 'cde'], 'abcde')", + "(['a', 'aa'], 'a')", + "(['ab', 'abc'], 'abc')", + "(['abc', 'ab'], '')", + "(['a', 'b', 'c', 'd'], 'abcd')", + "(['d', 'c', 'b', 'a'], 'dcba')", + "(['ac', 'ab', 'b'], 'acb')" + ] + }, "body": " result = run_alien_order(Solution, words)\n assert_alien_order(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/balanced_binary_tree.json b/leetcode_py/cli/resources/leetcode/json/problems/balanced_binary_tree.json index 2d5db13..e8c45e0 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/balanced_binary_tree.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/balanced_binary_tree.json @@ -5,7 +5,9 @@ "problem_title": "Balanced Binary Tree", "difficulty": "Easy", "topics": "Tree, Depth-First Search, Binary Tree", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "Given a binary tree, determine if it is **height-balanced**.\n\nA height-balanced binary tree is a binary tree in which the depth of the two subtrees of every node never differs by more than one.", "_readme_examples": { "list": [ @@ -15,7 +17,9 @@ { "content": "![Example 2](https://assets.leetcode.com/uploads/2020/10/06/balance_2.jpg)\n\n```\nInput: root = [1,2,2,3,3,null,null,4,4]\nOutput: false\n```" }, - { "content": "```\nInput: root = []\nOutput: true\n```" } + { + "content": "```\nInput: root = []\nOutput: true\n```" + } ] }, "readme_constraints": "- The number of nodes in the tree is in the range `[0, 5000]`.\n- `-10^4 <= Node.val <= 10^4`", @@ -45,7 +49,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -53,7 +63,25 @@ "name": "test_is_balanced", "signature": "(self, root_list: list[int | None], expected: bool)", "parametrize": "root_list, expected", - "test_cases": "[([3, 9, 20, None, None, 15, 7], True), ([1, 2, 2, 3, 3, None, None, 4, 4], False), ([], True), ([1], True), ([1, 2], True), ([1, None, 2], True), ([1, 2, 3, 4], True), ([1, 2, 2, 3, None, None, 3, 4, None, None, 4], False), ([1, 2, 3], True), ([1, 2, None, 3], False), ([1, None, 2, None, 3], False), ([1, 2, 3, 4, 5, 6, 7], True), ([1, 2, 3, None, None, 4, None, None, 5], False), ([5, 1, 4, None, None, 3, 6], True), ([1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, None, None, 5, 5], True)]", + "test_cases": { + "list": [ + "([3, 9, 20, None, None, 15, 7], True)", + "([1, 2, 2, 3, 3, None, None, 4, 4], False)", + "([], True)", + "([1], True)", + "([1, 2], True)", + "([1, None, 2], True)", + "([1, 2, 3, 4], True)", + "([1, 2, 2, 3, None, None, 3, 4, None, None, 4], False)", + "([1, 2, 3], True)", + "([1, 2, None, 3], False)", + "([1, None, 2, None, 3], False)", + "([1, 2, 3, 4, 5, 6, 7], True)", + "([1, 2, 3, None, None, 4, None, None, 5], False)", + "([5, 1, 4, None, None, 3, 6], True)", + "([1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, None, None, 5, 5], True)" + ] + }, "body": " result = run_is_balanced(Solution, root_list)\n assert_is_balanced(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/basic_calculator.json b/leetcode_py/cli/resources/leetcode/json/problems/basic_calculator.json index 74d4066..3865926 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/basic_calculator.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/basic_calculator.json @@ -5,13 +5,21 @@ "problem_title": "Basic Calculator", "difficulty": "Hard", "topics": "Math, String, Stack, Recursion", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "Given a string `s` representing a valid expression, implement a basic calculator to evaluate it, and return the result of the evaluation.\n\n**Note:** You are **not** allowed to use any built-in function which evaluates strings as mathematical expressions, such as `eval()`.", "_readme_examples": { "list": [ - { "content": "```\nInput: s = \"1 + 1\"\nOutput: 2\n```" }, - { "content": "```\nInput: s = \" 2-1 + 2 \"\nOutput: 3\n```" }, - { "content": "```\nInput: s = \"(1+(4+5+2)-3)+(6+8)\"\nOutput: 23\n```" } + { + "content": "```\nInput: s = \"1 + 1\"\nOutput: 2\n```" + }, + { + "content": "```\nInput: s = \" 2-1 + 2 \"\nOutput: 3\n```" + }, + { + "content": "```\nInput: s = \"(1+(4+5+2)-3)+(6+8)\"\nOutput: 23\n```" + } ] }, "readme_constraints": "- `1 <= s.length <= 3 * 10^5`\n- `s` consists of digits, `'+'`, `'-'`, `'('`, `')'`, and `' '`.\n- `s` represents a valid expression.\n- `'+'` is **not** used as a unary operation (i.e., `\"+1\"` and `\"+(2 + 3)\"` is invalid).\n- `'-'` could be used as a unary operation (i.e., `\"-1\"` and `\"-(2 + 3)\"` is valid).\n- There will be no two consecutive operators in the input.\n- Every number and running calculation will fit in a signed 32-bit integer.", @@ -41,7 +49,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -49,7 +63,34 @@ "name": "test_calculate", "signature": "(self, s: str, expected: int)", "parametrize": "s, expected", - "test_cases": "[('1 + 1', 2), (' 2-1 + 2 ', 3), ('(1+(4+5+2)-3)+(6+8)', 23), ('1', 1), ('-1', -1), ('-(1+2)', -3), ('2147483647', 2147483647), ('1-1+1', 1), ('0', 0), ('-0', 0), ('1+(2+3)', 6), ('(1+2)+3', 6), ('1-(2+3)', -4), ('(1-2)+3', 2), ('-(-1)', 1), ('-(-(-1))', -1), ('1000000-999999', 1), ('10+20-30+40', 40), ('((1+2)+(3+4))', 10), ('1+(2-(3+4))', -4), ('-(1+(2+3))', -6), (' 1 + 2 ', 3), ('123+456', 579), ('-2147483648', -2147483648)]", + "test_cases": { + "list": [ + "('1 + 1', 2)", + "(' 2-1 + 2 ', 3)", + "('(1+(4+5+2)-3)+(6+8)', 23)", + "('1', 1)", + "('-1', -1)", + "('-(1+2)', -3)", + "('2147483647', 2147483647)", + "('1-1+1', 1)", + "('0', 0)", + "('-0', 0)", + "('1+(2+3)', 6)", + "('(1+2)+3', 6)", + "('1-(2+3)', -4)", + "('(1-2)+3', 2)", + "('-(-1)', 1)", + "('-(-(-1))', -1)", + "('1000000-999999', 1)", + "('10+20-30+40', 40)", + "('((1+2)+(3+4))', 10)", + "('1+(2-(3+4))', -4)", + "('-(1+(2+3))', -6)", + "(' 1 + 2 ', 3)", + "('123+456', 579)", + "('-2147483648', -2147483648)" + ] + }, "body": " result = run_calculate(Solution, s)\n assert_calculate(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/best_time_to_buy_and_sell_stock.json b/leetcode_py/cli/resources/leetcode/json/problems/best_time_to_buy_and_sell_stock.json index 7e4ca68..31a1cb4 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/best_time_to_buy_and_sell_stock.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/best_time_to_buy_and_sell_stock.json @@ -5,7 +5,9 @@ "problem_title": "Best Time to Buy and Sell Stock", "difficulty": "Easy", "topics": "Array, Dynamic Programming", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "You are given an array `prices` where `prices[i]` is the price of a given stock on the ith day.\n\nYou want to maximize your profit by choosing a **single day** to buy one stock and choosing a **different day in the future** to sell that stock.\n\nReturn *the maximum profit you can achieve from this transaction*. If you cannot achieve any profit, return `0`.", "_readme_examples": { "list": [ @@ -44,7 +46,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -52,7 +60,25 @@ "name": "test_max_profit", "signature": "(self, prices: list[int], expected: int)", "parametrize": "prices, expected", - "test_cases": "[([7, 1, 5, 3, 6, 4], 5), ([7, 6, 4, 3, 1], 0), ([1, 2, 3, 4, 5], 4), ([5, 4, 3, 2, 1], 0), ([1], 0), ([2, 1], 0), ([1, 2], 1), ([3, 2, 6, 5, 0, 3], 4), ([2, 4, 1], 2), ([1, 5, 3, 6, 4], 5), ([10, 1, 5, 6, 7, 1], 6), ([6, 1, 3, 2, 4, 7], 6), ([1, 4, 2], 3), ([3, 3, 5, 0, 0, 3, 1, 4], 4), ([2, 1, 2, 1, 0, 1, 2], 2)]", + "test_cases": { + "list": [ + "([7, 1, 5, 3, 6, 4], 5)", + "([7, 6, 4, 3, 1], 0)", + "([1, 2, 3, 4, 5], 4)", + "([5, 4, 3, 2, 1], 0)", + "([1], 0)", + "([2, 1], 0)", + "([1, 2], 1)", + "([3, 2, 6, 5, 0, 3], 4)", + "([2, 4, 1], 2)", + "([1, 5, 3, 6, 4], 5)", + "([10, 1, 5, 6, 7, 1], 6)", + "([6, 1, 3, 2, 4, 7], 6)", + "([1, 4, 2], 3)", + "([3, 3, 5, 0, 0, 3, 1, 4], 4)", + "([2, 1, 2, 1, 0, 1, 2], 2)" + ] + }, "body": " result = run_max_profit(Solution, prices)\n assert_max_profit(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/binary_search.json b/leetcode_py/cli/resources/leetcode/json/problems/binary_search.json index 3166d10..6b0ef9b 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/binary_search.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/binary_search.json @@ -5,7 +5,9 @@ "problem_title": "Binary Search", "difficulty": "Easy", "topics": "Array, Binary Search", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "Given an array of integers `nums` which is sorted in ascending order, and an integer `target`, write a function to search `target` in `nums`. If `target` exists, then return its index. Otherwise, return `-1`.\n\nYou must write an algorithm with `O(log n)` runtime complexity.", "_readme_examples": { "list": [ @@ -44,7 +46,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -52,7 +60,23 @@ "name": "test_search", "signature": "(self, nums: list[int], target: int, expected: int)", "parametrize": "nums, target, expected", - "test_cases": "[([-1, 0, 3, 5, 9, 12], 9, 4), ([-1, 0, 3, 5, 9, 12], 2, -1), ([5], 5, 0), ([5], -5, -1), ([1, 3, 5, 7, 9], 1, 0), ([1, 3, 5, 7, 9], 9, 4), ([1, 3, 5, 7, 9], 4, -1), ([1, 3], 1, 0), ([1, 3], 3, 1), ([1, 3], 2, -1), ([-5, -2, 0, 3, 7], -2, 1), ([-5, -2, 0, 3, 7], 0, 2), ([-5, -2, 0, 3, 7], -1, -1)]", + "test_cases": { + "list": [ + "([-1, 0, 3, 5, 9, 12], 9, 4)", + "([-1, 0, 3, 5, 9, 12], 2, -1)", + "([5], 5, 0)", + "([5], -5, -1)", + "([1, 3, 5, 7, 9], 1, 0)", + "([1, 3, 5, 7, 9], 9, 4)", + "([1, 3, 5, 7, 9], 4, -1)", + "([1, 3], 1, 0)", + "([1, 3], 3, 1)", + "([1, 3], 2, -1)", + "([-5, -2, 0, 3, 7], -2, 1)", + "([-5, -2, 0, 3, 7], 0, 2)", + "([-5, -2, 0, 3, 7], -1, -1)" + ] + }, "body": " result = run_search(Solution, nums, target)\n assert_search(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/binary_tree_level_order_traversal.json b/leetcode_py/cli/resources/leetcode/json/problems/binary_tree_level_order_traversal.json index e1cde47..38a10bd 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/binary_tree_level_order_traversal.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/binary_tree_level_order_traversal.json @@ -5,15 +5,21 @@ "problem_title": "Binary Tree Level Order Traversal", "difficulty": "Medium", "topics": "Tree, Breadth-First Search, Binary Tree", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "Given the `root` of a binary tree, return the level order traversal of its nodes' values. (i.e., from left to right, level by level).", "_readme_examples": { "list": [ { "content": "![Example 1](https://assets.leetcode.com/uploads/2021/02/19/tree1.jpg)\n\n```\nInput: root = [3,9,20,null,null,15,7]\nOutput: [[3],[9,20],[15,7]]\n```" }, - { "content": "```\nInput: root = [1]\nOutput: [[1]]\n```" }, - { "content": "```\nInput: root = []\nOutput: []\n```" } + { + "content": "```\nInput: root = [1]\nOutput: [[1]]\n```" + }, + { + "content": "```\nInput: root = []\nOutput: []\n```" + } ] }, "readme_constraints": "- The number of nodes in the tree is in the range [0, 2000]\n- -1000 <= Node.val <= 1000", @@ -43,7 +49,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -51,7 +63,23 @@ "name": "test_level_order", "signature": "(self, root_list: list[int | None], expected: list[list[int]])", "parametrize": "root_list, expected", - "test_cases": "[([3, 9, 20, None, None, 15, 7], [[3], [9, 20], [15, 7]]), ([1], [[1]]), ([], []), ([1, 2, 3, 4, 5, 6, 7], [[1], [2, 3], [4, 5, 6, 7]]), ([1, 2, None, 3, None, 4, None, 5], [[1], [2], [3], [4], [5]]), ([1, None, 2, None, 3], [[1], [2], [3]]), ([1, 2, None, 3, None], [[1], [2], [3]]), ([0], [[0]]), ([-1, -2, -3], [[-1], [-2, -3]]), ([1, 2, 3, None, None, None, 4], [[1], [2, 3], [4]]), ([5, 4, 8, 11, None, 13, 4, 7, 2, None, None, None, 1], [[5], [4, 8], [11, 13, 4], [7, 2, 1]]), ([1, 2, 2, 3, 3, 3, 3], [[1], [2, 2], [3, 3, 3, 3]]), ([1, None, None], [[1]])]", + "test_cases": { + "list": [ + "([3, 9, 20, None, None, 15, 7], [[3], [9, 20], [15, 7]])", + "([1], [[1]])", + "([], [])", + "([1, 2, 3, 4, 5, 6, 7], [[1], [2, 3], [4, 5, 6, 7]])", + "([1, 2, None, 3, None, 4, None, 5], [[1], [2], [3], [4], [5]])", + "([1, None, 2, None, 3], [[1], [2], [3]])", + "([1, 2, None, 3, None], [[1], [2], [3]])", + "([0], [[0]])", + "([-1, -2, -3], [[-1], [-2, -3]])", + "([1, 2, 3, None, None, None, 4], [[1], [2, 3], [4]])", + "([5, 4, 8, 11, None, 13, 4, 7, 2, None, None, None, 1], [[5], [4, 8], [11, 13, 4], [7, 2, 1]])", + "([1, 2, 2, 3, 3, 3, 3], [[1], [2, 2], [3, 3, 3, 3]])", + "([1, None, None], [[1]])" + ] + }, "body": " result = run_level_order(Solution, root_list)\n assert_level_order(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/binary_tree_right_side_view.json b/leetcode_py/cli/resources/leetcode/json/problems/binary_tree_right_side_view.json index 8852d72..19d66da 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/binary_tree_right_side_view.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/binary_tree_right_side_view.json @@ -5,7 +5,9 @@ "problem_title": "Binary Tree Right Side View", "difficulty": "Medium", "topics": "Tree, Depth-First Search, Breadth-First Search, Binary Tree", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "Given the `root` of a binary tree, imagine yourself standing on the **right side** of it, return *the values of the nodes you can see ordered from top to bottom*.", "_readme_examples": { "list": [ @@ -15,8 +17,12 @@ { "content": "![Example 2](https://assets.leetcode.com/uploads/2024/11/24/tmpkpe40xeh-1.png)\n\n```\nInput: root = [1,2,3,4,null,null,null,5]\nOutput: [1,3,4,5]\n```" }, - { "content": "```\nInput: root = [1,null,3]\nOutput: [1,3]\n```" }, - { "content": "```\nInput: root = []\nOutput: []\n```" } + { + "content": "```\nInput: root = [1,null,3]\nOutput: [1,3]\n```" + }, + { + "content": "```\nInput: root = []\nOutput: []\n```" + } ] }, "readme_constraints": "- The number of nodes in the tree is in the range `[0, 100]`.\n- `-100 <= Node.val <= 100`", @@ -46,7 +52,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -54,7 +66,24 @@ "name": "test_right_side_view", "signature": "(self, root_list: list[int | None], expected: list[int])", "parametrize": "root_list, expected", - "test_cases": "[([1, 2, 3, None, 5, None, 4], [1, 3, 4]), ([1, 2, 3, 4, None, None, None, 5], [1, 3, 4, 5]), ([1, None, 3], [1, 3]), ([], []), ([1], [1]), ([1, 2], [1, 2]), ([1, None, 2], [1, 2]), ([1, 2, 3], [1, 3]), ([1, 2, None, 4], [1, 2, 4]), ([1, 2, 3, 4, 5, 6, 7], [1, 3, 7]), ([1, 2, 3, None, None, 4, 5], [1, 3, 5]), ([5, 4, 6, None, None, None, 7], [5, 6, 7]), ([1, 2, 3, 4, 5, None, None, 8], [1, 3, 5, 8]), ([10, 5, 15, None, 6, 12, 20], [10, 15, 20])]", + "test_cases": { + "list": [ + "([1, 2, 3, None, 5, None, 4], [1, 3, 4])", + "([1, 2, 3, 4, None, None, None, 5], [1, 3, 4, 5])", + "([1, None, 3], [1, 3])", + "([], [])", + "([1], [1])", + "([1, 2], [1, 2])", + "([1, None, 2], [1, 2])", + "([1, 2, 3], [1, 3])", + "([1, 2, None, 4], [1, 2, 4])", + "([1, 2, 3, 4, 5, 6, 7], [1, 3, 7])", + "([1, 2, 3, None, None, 4, 5], [1, 3, 5])", + "([5, 4, 6, None, None, None, 7], [5, 6, 7])", + "([1, 2, 3, 4, 5, None, None, 8], [1, 3, 5, 8])", + "([10, 5, 15, None, 6, 12, 20], [10, 15, 20])" + ] + }, "body": " result = run_right_side_view(Solution, root_list)\n assert_right_side_view(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/climbing_stairs.json b/leetcode_py/cli/resources/leetcode/json/problems/climbing_stairs.json index fd3db16..a28fdf7 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/climbing_stairs.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/climbing_stairs.json @@ -5,7 +5,9 @@ "problem_title": "Climbing Stairs", "difficulty": "Easy", "topics": "Math, Dynamic Programming, Memoization", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "You are climbing a staircase. It takes `n` steps to reach the top.\n\nEach time you can either climb `1` or `2` steps. In how many distinct ways can you climb to the top?", "_readme_examples": { "list": [ @@ -44,7 +46,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -52,7 +60,27 @@ "name": "test_climb_stairs", "signature": "(self, n: int, expected: int)", "parametrize": "n, expected", - "test_cases": "[(1, 1), (2, 2), (3, 3), (4, 5), (5, 8), (6, 13), (7, 21), (8, 34), (9, 55), (10, 89), (15, 987), (20, 10946), (25, 121393), (30, 1346269), (35, 14930352), (40, 165580141), (45, 1836311903)]", + "test_cases": { + "list": [ + "(1, 1)", + "(2, 2)", + "(3, 3)", + "(4, 5)", + "(5, 8)", + "(6, 13)", + "(7, 21)", + "(8, 34)", + "(9, 55)", + "(10, 89)", + "(15, 987)", + "(20, 10946)", + "(25, 121393)", + "(30, 1346269)", + "(35, 14930352)", + "(40, 165580141)", + "(45, 1836311903)" + ] + }, "body": " result = run_climb_stairs(Solution, n)\n assert_climb_stairs(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/clone_graph.json b/leetcode_py/cli/resources/leetcode/json/problems/clone_graph.json index 75f6244..6884b92 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/clone_graph.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/clone_graph.json @@ -5,7 +5,9 @@ "problem_title": "Clone Graph", "difficulty": "Medium", "topics": "Hash Table, Depth-First Search, Breadth-First Search, Graph", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "Given a reference of a node in a **connected** undirected graph.\n\nReturn a **deep copy** (clone) of the graph.\n\nEach node in the graph contains a value (`int`) and a list (`List[Node]`) of its neighbors.\n\n```\nclass Node {\n public int val;\n public List neighbors;\n}\n```\n\n**Test case format:**\n\nFor simplicity, each node's value is the same as the node's index (1-indexed). For example, the first node with `val == 1`, the second node with `val == 2`, and so on. The graph is represented in the test case using an adjacency list.\n\n**An adjacency list** is a collection of unordered **lists** used to represent a finite graph. Each list describes the set of neighbors of a node in the graph.\n\nThe given node will always be the first node with `val = 1`. You must return the **copy of the given node** as a reference to the cloned graph.", "_readme_examples": { "list": [ @@ -47,7 +49,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -55,7 +63,73 @@ "name": "test_clone_graph", "signature": "(self, adj_list: list[list[int]])", "parametrize": "adj_list", - "test_cases": "[[[2, 4], [1, 3], [2, 4], [1, 3]], [[]], [], [[2], [1]], [[2, 3], [1], [1]], [[2], [3], [4], []], [[2, 3, 4], [1], [1], [1]], [[2, 3], [1, 3], [1, 2]], [[2, 5], [1, 3], [2, 4], [3, 5], [1, 4]], [[2, 3], [1, 4], [1, 4], [2, 3]], [[2, 3, 4, 5], [1], [1], [1], [1]], [[2], [3], [4], [5], []]]", + "test_cases": { + "list": [ + "[[2", + "4]", + "[1", + "3]", + "[2", + "4]", + "[1", + "3]]", + "[[]]", + "[]", + "[[2]", + "[1]]", + "[[2", + "3]", + "[1]", + "[1]]", + "[[2]", + "[3]", + "[4]", + "[]]", + "[[2", + "3", + "4]", + "[1]", + "[1]", + "[1]]", + "[[2", + "3]", + "[1", + "3]", + "[1", + "2]]", + "[[2", + "5]", + "[1", + "3]", + "[2", + "4]", + "[3", + "5]", + "[1", + "4]]", + "[[2", + "3]", + "[1", + "4]", + "[1", + "4]", + "[2", + "3]]", + "[[2", + "3", + "4", + "5]", + "[1]", + "[1]", + "[1]", + "[1]]", + "[[2]", + "[3]", + "[4]", + "[5]", + "[]]" + ] + }, "body": " result = run_clone_graph(Solution, adj_list)\n assert_clone_graph(result, adj_list)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/coin_change.json b/leetcode_py/cli/resources/leetcode/json/problems/coin_change.json index a668904..59befb0 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/coin_change.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/coin_change.json @@ -5,15 +5,21 @@ "problem_title": "Coin Change", "difficulty": "Medium", "topics": "Array, Dynamic Programming, Breadth-First Search", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "You are given an integer array `coins` representing coins of different denominations and an integer `amount` representing a total amount of money.\n\nReturn the fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any combination of the coins, return `-1`.\n\nYou may assume that you have an infinite number of each kind of coin.", "_readme_examples": { "list": [ { "content": "```\nInput: coins = [1,2,5], amount = 11\nOutput: 3\n```\n**Explanation:** 11 = 5 + 5 + 1" }, - { "content": "```\nInput: coins = [2], amount = 3\nOutput: -1\n```" }, - { "content": "```\nInput: coins = [1], amount = 0\nOutput: 0\n```" } + { + "content": "```\nInput: coins = [2], amount = 3\nOutput: -1\n```" + }, + { + "content": "```\nInput: coins = [1], amount = 0\nOutput: 0\n```" + } ] }, "readme_constraints": "- `1 <= coins.length <= 12`\n- `1 <= coins[i] <= 2^31 - 1`\n- `0 <= amount <= 10^4`", @@ -43,7 +49,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -51,7 +63,25 @@ "name": "test_coin_change", "signature": "(self, coins: list[int], amount: int, expected: int)", "parametrize": "coins, amount, expected", - "test_cases": "[([1, 2, 5], 11, 3), ([2], 3, -1), ([1], 0, 0), ([1, 3, 4], 6, 2), ([2, 5, 10, 1], 27, 4), ([5], 3, -1), ([1], 1, 1), ([1, 2], 2, 1), ([186, 419, 83, 408], 6249, 20), ([1, 5, 10, 25], 30, 2), ([2, 3, 5], 9, 3), ([1, 4, 5], 8, 2), ([3, 5], 1, -1), ([1, 2, 5], 100, 20), ([7, 11], 14, 2)]", + "test_cases": { + "list": [ + "([1, 2, 5], 11, 3)", + "([2], 3, -1)", + "([1], 0, 0)", + "([1, 3, 4], 6, 2)", + "([2, 5, 10, 1], 27, 4)", + "([5], 3, -1)", + "([1], 1, 1)", + "([1, 2], 2, 1)", + "([186, 419, 83, 408], 6249, 20)", + "([1, 5, 10, 25], 30, 2)", + "([2, 3, 5], 9, 3)", + "([1, 4, 5], 8, 2)", + "([3, 5], 1, -1)", + "([1, 2, 5], 100, 20)", + "([7, 11], 14, 2)" + ] + }, "body": " result = run_coin_change(Solution, coins, amount)\n assert_coin_change(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/combination_sum.json b/leetcode_py/cli/resources/leetcode/json/problems/combination_sum.json index 74786a8..ebdc36a 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/combination_sum.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/combination_sum.json @@ -5,7 +5,9 @@ "problem_title": "Combination Sum", "difficulty": "Medium", "topics": "Array, Backtracking", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "Given an array of **distinct** integers `candidates` and a target integer `target`, return *a list of all **unique combinations** of* `candidates` *where the chosen numbers sum to* `target`. You may return the combinations in **any order**.\n\nThe **same** number may be chosen from `candidates` an **unlimited number of times**. Two combinations are unique if the frequency of at least one of the chosen numbers is different.\n\nThe test cases are generated such that the number of unique combinations that sum up to `target` is less than `150` combinations for the given input.", "_readme_examples": { "list": [ @@ -15,7 +17,9 @@ { "content": "```\nInput: candidates = [2,3,5], target = 8\nOutput: [[2,2,2,2],[2,3,3],[3,5]]\n```" }, - { "content": "```\nInput: candidates = [2], target = 1\nOutput: []\n```" } + { + "content": "```\nInput: candidates = [2], target = 1\nOutput: []\n```" + } ] }, "readme_constraints": "- 1 <= candidates.length <= 30\n- 2 <= candidates[i] <= 40\n- All elements of candidates are distinct.\n- 1 <= target <= 40", @@ -45,7 +49,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -53,7 +63,22 @@ "name": "test_combination_sum", "signature": "(self, candidates: list[int], target: int, expected: list[list[int]])", "parametrize": "candidates, target, expected", - "test_cases": "[([2, 3, 6, 7], 7, [[2, 2, 3], [7]]), ([2, 3, 5], 8, [[2, 2, 2, 2], [2, 3, 3], [3, 5]]), ([2], 1, []), ([2, 3], 1, []), ([3, 5], 3, [[3]]), ([2, 4], 6, [[2, 2, 2], [2, 4]]), ([5], 5, [[5]]), ([2, 3, 4], 6, [[2, 2, 2], [2, 4], [3, 3]]), ([4, 2, 8], 8, [[2, 2, 2, 2], [2, 2, 4], [4, 4], [8]]), ([3, 4, 5], 9, [[3, 3, 3], [4, 5]]), ([6, 3, 2], 6, [[2, 2, 2], [3, 3], [6]]), ([2, 7], 9, [[2, 7]])]", + "test_cases": { + "list": [ + "([2, 3, 6, 7], 7, [[2, 2, 3], [7]])", + "([2, 3, 5], 8, [[2, 2, 2, 2], [2, 3, 3], [3, 5]])", + "([2], 1, [])", + "([2, 3], 1, [])", + "([3, 5], 3, [[3]])", + "([2, 4], 6, [[2, 2, 2], [2, 4]])", + "([5], 5, [[5]])", + "([2, 3, 4], 6, [[2, 2, 2], [2, 4], [3, 3]])", + "([4, 2, 8], 8, [[2, 2, 2, 2], [2, 2, 4], [4, 4], [8]])", + "([3, 4, 5], 9, [[3, 3, 3], [4, 5]])", + "([6, 3, 2], 6, [[2, 2, 2], [3, 3], [6]])", + "([2, 7], 9, [[2, 7]])" + ] + }, "body": " result = run_combination_sum(Solution, candidates, target)\n assert_combination_sum(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/construct_binary_tree_from_preorder_and_inorder_traversal.json b/leetcode_py/cli/resources/leetcode/json/problems/construct_binary_tree_from_preorder_and_inorder_traversal.json index 6546085..68e650e 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/construct_binary_tree_from_preorder_and_inorder_traversal.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/construct_binary_tree_from_preorder_and_inorder_traversal.json @@ -5,14 +5,18 @@ "problem_title": "Construct Binary Tree from Preorder and Inorder Traversal", "difficulty": "Medium", "topics": "Array, Hash Table, Divide and Conquer, Tree, Binary Tree", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "Given two integer arrays `preorder` and `inorder` where `preorder` is the preorder traversal of a binary tree and `inorder` is the inorder traversal of the same tree, construct and return the binary tree.", "_readme_examples": { "list": [ { "content": "![Example 1](https://assets.leetcode.com/uploads/2021/02/19/tree.jpg)\n\n```\nInput: preorder = [3,9,20,15,7], inorder = [9,3,15,20,7]\nOutput: [3,9,20,null,null,15,7]\n```" }, - { "content": "```\nInput: preorder = [-1], inorder = [-1]\nOutput: [-1]\n```" } + { + "content": "```\nInput: preorder = [-1], inorder = [-1]\nOutput: [-1]\n```" + } ] }, "readme_constraints": "- 1 <= preorder.length <= 3000\n- inorder.length == preorder.length\n- -3000 <= preorder[i], inorder[i] <= 3000\n- preorder and inorder consist of unique values.\n- Each value of inorder also appears in preorder.\n- preorder is guaranteed to be the preorder traversal of the tree.\n- inorder is guaranteed to be the inorder traversal of the tree.", @@ -42,7 +46,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -50,7 +60,26 @@ "name": "test_build_tree", "signature": "(self, preorder: list[int], inorder: list[int], expected_list: list[int | None])", "parametrize": "preorder, inorder, expected_list", - "test_cases": "[([], [], []), ([1], [1], [1]), ([3, 9, 20, 15, 7], [9, 3, 15, 20, 7], [3, 9, 20, None, None, 15, 7]), ([-1], [-1], [-1]), ([1, 2], [2, 1], [1, 2]), ([1, 2], [1, 2], [1, None, 2]), ([1, 2, 3], [2, 1, 3], [1, 2, 3]), ([1, 2, 4, 5, 3, 6], [4, 2, 5, 1, 6, 3], [1, 2, 3, 4, 5, 6]), ([1, 2, 3, 4], [1, 2, 3, 4], [1, None, 2, None, 3, None, 4]), ([4, 3, 2, 1], [1, 2, 3, 4], [4, 3, None, 2, None, 1]), ([10, 5, 1, 7, 40, 50], [1, 5, 7, 10, 40, 50], [10, 5, 40, 1, 7, None, 50]), ([1, 3, 2], [1, 2, 3], [1, None, 3, 2]), ([2, 1, 3], [1, 2, 3], [2, 1, 3]), ([5, 3, 2, 1, 4, 6, 7], [1, 2, 3, 4, 5, 6, 7], [5, 3, 6, 2, 4, None, 7, 1]), ([7, 3, 2, 1, 5, 4, 6, 10, 9, 11], [1, 2, 3, 4, 5, 6, 7, 9, 10, 11], [7, 3, 10, 2, 5, 9, 11, 1, None, 4, 6]), ([-3000, -2999, -2998], [-2998, -2999, -3000], [-3000, -2999, None, -2998])]", + "test_cases": { + "list": [ + "([], [], [])", + "([1], [1], [1])", + "([3, 9, 20, 15, 7], [9, 3, 15, 20, 7], [3, 9, 20, None, None, 15, 7])", + "([-1], [-1], [-1])", + "([1, 2], [2, 1], [1, 2])", + "([1, 2], [1, 2], [1, None, 2])", + "([1, 2, 3], [2, 1, 3], [1, 2, 3])", + "([1, 2, 4, 5, 3, 6], [4, 2, 5, 1, 6, 3], [1, 2, 3, 4, 5, 6])", + "([1, 2, 3, 4], [1, 2, 3, 4], [1, None, 2, None, 3, None, 4])", + "([4, 3, 2, 1], [1, 2, 3, 4], [4, 3, None, 2, None, 1])", + "([10, 5, 1, 7, 40, 50], [1, 5, 7, 10, 40, 50], [10, 5, 40, 1, 7, None, 50])", + "([1, 3, 2], [1, 2, 3], [1, None, 3, 2])", + "([2, 1, 3], [1, 2, 3], [2, 1, 3])", + "([5, 3, 2, 1, 4, 6, 7], [1, 2, 3, 4, 5, 6, 7], [5, 3, 6, 2, 4, None, 7, 1])", + "([7, 3, 2, 1, 5, 4, 6, 10, 9, 11], [1, 2, 3, 4, 5, 6, 7, 9, 10, 11], [7, 3, 10, 2, 5, 9, 11, 1, None, 4, 6])", + "([-3000, -2999, -2998], [-2998, -2999, -3000], [-3000, -2999, None, -2998])" + ] + }, "body": " result = run_build_tree(Solution, preorder, inorder)\n assert_build_tree(result, expected_list)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/container_with_most_water.json b/leetcode_py/cli/resources/leetcode/json/problems/container_with_most_water.json index f7c23cb..344ecdf 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/container_with_most_water.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/container_with_most_water.json @@ -5,14 +5,18 @@ "problem_title": "Container With Most Water", "difficulty": "Medium", "topics": "Array, Two Pointers, Greedy", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "You are given an integer array `height` of length `n`. There are `n` vertical lines drawn such that the two endpoints of the `i`th line are `(i, 0)` and `(i, height[i])`.\n\nFind two lines that together with the x-axis form a container, such that the container contains the most water.\n\nReturn the maximum amount of water a container can store.\n\nNotice that you may not slant the container.", "_readme_examples": { "list": [ { "content": "![Example 1](https://s3-lc-upload.s3.amazonaws.com/uploads/2018/07/17/question_11.jpg)\n\n```\nInput: height = [1,8,6,2,5,4,8,3,7]\nOutput: 49\n```\n**Explanation:** The above vertical lines are represented by array [1,8,6,2,5,4,8,3,7]. In this case, the max area of water (blue section) the container can contain is 49." }, - { "content": "```\nInput: height = [1,1]\nOutput: 1\n```" } + { + "content": "```\nInput: height = [1,1]\nOutput: 1\n```" + } ] }, "readme_constraints": "- n == height.length\n- 2 <= n <= 10^5\n- 0 <= height[i] <= 10^4", @@ -42,7 +46,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -50,7 +60,22 @@ "name": "test_max_area", "signature": "(self, height: list[int], expected: int)", "parametrize": "height, expected", - "test_cases": "[([1,8,6,2,5,4,8,3,7], 49), ([1,1], 1), ([1,2,1], 2), ([2,1], 1), ([1,2,4,3], 4), ([1,3,2,5,25,24,5], 24), ([2,3,4,5,18,17,6], 17), ([1,2,3,4,5], 6), ([5,4,3,2,1], 6), ([0,2], 0), ([3,9,3,4,7,2,12,6], 45), ([1,0,0,0,0,0,0,2,2], 8)]", + "test_cases": { + "list": [ + "([1,8,6,2,5,4,8,3,7], 49)", + "([1,1], 1)", + "([1,2,1], 2)", + "([2,1], 1)", + "([1,2,4,3], 4)", + "([1,3,2,5,25,24,5], 24)", + "([2,3,4,5,18,17,6], 17)", + "([1,2,3,4,5], 6)", + "([5,4,3,2,1], 6)", + "([0,2], 0)", + "([3,9,3,4,7,2,12,6], 45)", + "([1,0,0,0,0,0,0,2,2], 8)" + ] + }, "body": " result = run_max_area(Solution, height)\n assert_max_area(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/contains_duplicate.json b/leetcode_py/cli/resources/leetcode/json/problems/contains_duplicate.json index b623280..789cf43 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/contains_duplicate.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/contains_duplicate.json @@ -5,7 +5,9 @@ "problem_title": "Contains Duplicate", "difficulty": "Easy", "topics": "Array, Hash Table, Sorting", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "Given an integer array `nums`, return `true` if any value appears **at least twice** in the array, and return `false` if every element is distinct.", "_readme_examples": { "list": [ @@ -15,7 +17,9 @@ { "content": "```\nInput: nums = [1,2,3,4]\nOutput: false\n```\n**Explanation:** All elements are distinct." }, - { "content": "```\nInput: nums = [1,1,1,3,3,4,3,2,4,2]\nOutput: true\n```" } + { + "content": "```\nInput: nums = [1,1,1,3,3,4,3,2,4,2]\nOutput: true\n```" + } ] }, "readme_constraints": "- 1 <= nums.length <= 10^5\n- -10^9 <= nums[i] <= 10^9", @@ -45,7 +49,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -53,7 +63,22 @@ "name": "test_contains_duplicate", "signature": "(self, nums: list[int], expected: bool)", "parametrize": "nums, expected", - "test_cases": "[([1, 2, 3, 1], True), ([1, 2, 3, 4], False), ([1, 1, 1, 3, 3, 4, 3, 2, 4, 2], True), ([1], False), ([1, 1], True), ([0, 0], True), ([-1, -1], True), ([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], False), ([10, 9, 8, 7, 6, 5, 4, 3, 2, 1], False), ([1, 2, 3, 4, 5, 1], True), ([-1000000000, 1000000000, -1000000000], True), ([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0], True)]", + "test_cases": { + "list": [ + "([1, 2, 3, 1], True)", + "([1, 2, 3, 4], False)", + "([1, 1, 1, 3, 3, 4, 3, 2, 4, 2], True)", + "([1], False)", + "([1, 1], True)", + "([0, 0], True)", + "([-1, -1], True)", + "([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], False)", + "([10, 9, 8, 7, 6, 5, 4, 3, 2, 1], False)", + "([1, 2, 3, 4, 5, 1], True)", + "([-1000000000, 1000000000, -1000000000], True)", + "([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0], True)" + ] + }, "body": " result = run_contains_duplicate(Solution, nums)\n assert_contains_duplicate(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/contiguous_array.json b/leetcode_py/cli/resources/leetcode/json/problems/contiguous_array.json index 5524dc8..a23e9a2 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/contiguous_array.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/contiguous_array.json @@ -5,7 +5,9 @@ "problem_title": "Contiguous Array", "difficulty": "Medium", "topics": "Array, Hash Table, Prefix Sum", - "_tags": { "list": ["grind"] }, + "_tags": { + "list": ["grind"] + }, "readme_description": "Given a binary array `nums`, return *the maximum length of a contiguous subarray with an equal number of* `0` *and* `1`.", "_readme_examples": { "list": [ @@ -47,7 +49,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -55,7 +63,27 @@ "name": "test_find_max_length", "signature": "(self, nums: list[int], expected: int)", "parametrize": "nums, expected", - "test_cases": "[([0, 1], 2), ([0, 1, 0], 2), ([0, 1, 1, 1, 1, 1, 0, 0, 0], 6), ([0], 0), ([1], 0), ([0, 0], 0), ([1, 1], 0), ([0, 0, 1, 0, 0, 1, 1, 0], 6), ([1, 0, 1, 0, 1], 4), ([0, 1, 1, 0, 1, 1, 1, 0], 4), ([1, 1, 1, 1, 1, 1, 1, 1], 0), ([0, 0, 0, 0, 0, 0, 0, 0], 0), ([1, 0, 1, 1, 0, 0, 1, 0, 1], 8), ([0, 1, 0, 1, 0, 1, 0, 1], 8), ([1, 0, 0, 1, 1, 0, 1, 0, 0, 1], 10), ([0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0], 10), ([1, 1, 0, 0, 1, 1, 0, 0, 1, 1], 8)]", + "test_cases": { + "list": [ + "([0, 1], 2)", + "([0, 1, 0], 2)", + "([0, 1, 1, 1, 1, 1, 0, 0, 0], 6)", + "([0], 0)", + "([1], 0)", + "([0, 0], 0)", + "([1, 1], 0)", + "([0, 0, 1, 0, 0, 1, 1, 0], 6)", + "([1, 0, 1, 0, 1], 4)", + "([0, 1, 1, 0, 1, 1, 1, 0], 4)", + "([1, 1, 1, 1, 1, 1, 1, 1], 0)", + "([0, 0, 0, 0, 0, 0, 0, 0], 0)", + "([1, 0, 1, 1, 0, 0, 1, 0, 1], 8)", + "([0, 1, 0, 1, 0, 1, 0, 1], 8)", + "([1, 0, 0, 1, 1, 0, 1, 0, 0, 1], 10)", + "([0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0], 10)", + "([1, 1, 0, 0, 1, 1, 0, 0, 1, 1], 8)" + ] + }, "body": " result = run_find_max_length(Solution, nums)\n assert_find_max_length(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/course_schedule.json b/leetcode_py/cli/resources/leetcode/json/problems/course_schedule.json index 44fc4db..ce66b44 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/course_schedule.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/course_schedule.json @@ -5,7 +5,9 @@ "problem_title": "Course Schedule", "difficulty": "Medium", "topics": "Depth-First Search, Breadth-First Search, Graph, Topological Sort", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "There are a total of `numCourses` courses you have to take, labeled from `0` to `numCourses - 1`. You are given an array `prerequisites` where `prerequisites[i] = [ai, bi]` indicates that you **must** take course `bi` first if you want to take course `ai`.\n\n- For example, the pair `[0, 1]`, indicates that to take course `0` you have to first take course `1`.\n\nReturn `true` if you can finish all courses. Otherwise, return `false`.", "_readme_examples": { "list": [ @@ -44,7 +46,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -52,7 +60,22 @@ "name": "test_can_finish", "signature": "(self, num_courses: int, prerequisites: list[list[int]], expected: bool)", "parametrize": "num_courses, prerequisites, expected", - "test_cases": "[(2, [[1, 0]], True), (2, [[1, 0], [0, 1]], False), (1, [], True), (3, [[1, 0], [2, 1]], True), (4, [[1, 0], [2, 1], [3, 2], [1, 3]], False), (3, [[0, 1], [0, 2], [1, 2]], True), (4, [[0, 1], [1, 2], [2, 3], [3, 1]], False), (6, [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]], True), (3, [[1, 0], [2, 0]], True), (5, [[0, 1], [1, 2], [2, 3], [3, 4], [4, 0]], False), (4, [[1, 0], [2, 0], [3, 1], [3, 2]], True), (5, [[1, 0], [2, 1], [3, 2], [4, 3], [0, 4]], False)]", + "test_cases": { + "list": [ + "(2, [[1, 0]], True)", + "(2, [[1, 0], [0, 1]], False)", + "(1, [], True)", + "(3, [[1, 0], [2, 1]], True)", + "(4, [[1, 0], [2, 1], [3, 2], [1, 3]], False)", + "(3, [[0, 1], [0, 2], [1, 2]], True)", + "(4, [[0, 1], [1, 2], [2, 3], [3, 1]], False)", + "(6, [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]], True)", + "(3, [[1, 0], [2, 0]], True)", + "(5, [[0, 1], [1, 2], [2, 3], [3, 4], [4, 0]], False)", + "(4, [[1, 0], [2, 0], [3, 1], [3, 2]], True)", + "(5, [[1, 0], [2, 1], [3, 2], [4, 3], [0, 4]], False)" + ] + }, "body": " result = run_can_finish(Solution, num_courses, prerequisites)\n assert_can_finish(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/course_schedule_ii.json b/leetcode_py/cli/resources/leetcode/json/problems/course_schedule_ii.json index b2e918d..82bc5f5 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/course_schedule_ii.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/course_schedule_ii.json @@ -5,8 +5,9 @@ "problem_title": "Course Schedule II", "difficulty": "Medium", "topics": "Depth-First Search, Breadth-First Search, Graph, Topological Sort", - "_tags": { "list": ["grind"] }, - + "_tags": { + "list": ["grind"] + }, "readme_description": "There are a total of `numCourses` courses you have to take, labeled from `0` to `numCourses - 1`. You are given an array `prerequisites` where `prerequisites[i] = [ai, bi]` indicates that you **must** take course `bi` first if you want to take course `ai`.\n\n- For example, the pair `[0, 1]`, indicates that to take course `0` you have to first take course `1`.\n\nReturn the ordering of courses you should take to finish all courses. If there are many valid answers, return **any** of them. If it is impossible to finish all courses, return **an empty array**.", "_readme_examples": { "list": [ @@ -16,12 +17,13 @@ { "content": "```\nInput: numCourses = 4, prerequisites = [[1,0],[2,0],[3,1],[3,2]]\nOutput: [0,2,1,3]\nExplanation: There are a total of 4 courses to take. To take course 3 you should have finished both courses 1 and 2. Both courses 1 and 2 should be taken after you finished course 0.\nSo one correct course order is [0,1,2,3]. Another correct ordering is [0,2,1,3].\n```" }, - { "content": "```\nInput: numCourses = 1, prerequisites = []\nOutput: [0]\n```" } + { + "content": "```\nInput: numCourses = 1, prerequisites = []\nOutput: [0]\n```" + } ] }, "readme_constraints": "- `1 <= numCourses <= 2000`\n- `0 <= prerequisites.length <= numCourses * (numCourses - 1)`\n- `prerequisites[i].length == 2`\n- `0 <= ai, bi < numCourses`\n- `ai != bi`\n- All the pairs `[ai, bi]` are **distinct**.", "readme_additional": "", - "helpers_imports": "", "helpers_content": "", "helpers_run_name": "find_order", @@ -30,16 +32,13 @@ "helpers_assert_name": "find_order", "helpers_assert_signature": "(result: list[int], expected: list[int]) -> bool", "helpers_assert_body": " if not result and not expected:\n return True\n if len(result) != len(expected):\n return False\n # For topological sort, multiple valid answers exist\n # Just verify the result is a valid topological ordering\n assert len(result) == len(expected)\n assert set(result) == set(expected)\n return True", - "solution_imports": "", "solution_contents": "", "solution_class_content": "", - "test_imports": "import pytest\nfrom leetcode_py import logged_test\nfrom .helpers import assert_find_order, run_find_order\nfrom .solution import Solution", "test_content": "", "test_class_name": "CourseScheduleII", "test_class_content": " def setup_method(self):\n self.solution = Solution()", - "_solution_methods": { "list": [ { @@ -49,23 +48,47 @@ } ] }, - "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, - "_test_methods": { "list": [ { "name": "test_find_order", "signature": "(self, num_courses: int, prerequisites: list[list[int]], expected: list[int])", "parametrize": "num_courses, prerequisites, expected", - "test_cases": "[(2, [[1, 0]], [0, 1]), (4, [[1, 0], [2, 0], [3, 1], [3, 2]], [0, 2, 1, 3]), (1, [], [0]), (3, [[1, 0], [2, 1]], [0, 1, 2]), (2, [[1, 0], [0, 1]], []), (3, [[0, 1], [0, 2], [1, 2]], [2, 1, 0]), (4, [[1, 0], [2, 1], [3, 2]], [0, 1, 2, 3]), (3, [[1, 0], [1, 2], [0, 1]], []), (5, [[1, 4], [2, 4], [3, 1], [3, 2]], [4, 1, 2, 3, 0]), (6, [[3, 0], [3, 1], [4, 1], [4, 2], [5, 3], [5, 4]], [0, 1, 2, 3, 4, 5]), (0, [], []), (3, [], [0, 1, 2]), (4, [[0, 1], [1, 2], [2, 3], [3, 0]], []), (5, [[0, 1], [1, 2], [2, 3], [3, 4]], [0, 1, 2, 3, 4]), (3, [[0, 1], [1, 0], [2, 1]], []), (4, [[1, 0], [2, 0], [3, 0]], [0, 1, 2, 3]), (5, [[1, 0], [2, 1], [3, 2], [4, 3], [0, 4]], []), (7, [[1, 0], [2, 0], [3, 1], [4, 1], [5, 2], [6, 2]], [0, 1, 2, 3, 4, 5, 6])]", + "test_cases": { + "list": [ + "(2, [[1, 0]], [0, 1])", + "(4, [[1, 0], [2, 0], [3, 1], [3, 2]], [0, 2, 1, 3])", + "(1, [], [0])", + "(3, [[1, 0], [2, 1]], [0, 1, 2])", + "(2, [[1, 0], [0, 1]], [])", + "(3, [[0, 1], [0, 2], [1, 2]], [2, 1, 0])", + "(4, [[1, 0], [2, 1], [3, 2]], [0, 1, 2, 3])", + "(3, [[1, 0], [1, 2], [0, 1]], [])", + "(5, [[1, 4], [2, 4], [3, 1], [3, 2]], [4, 1, 2, 3, 0])", + "(6, [[3, 0], [3, 1], [4, 1], [4, 2], [5, 3], [5, 4]], [0, 1, 2, 3, 4, 5])", + "(0, [], [])", + "(3, [], [0, 1, 2])", + "(4, [[0, 1], [1, 2], [2, 3], [3, 0]], [])", + "(5, [[0, 1], [1, 2], [2, 3], [3, 4]], [0, 1, 2, 3, 4])", + "(3, [[0, 1], [1, 0], [2, 1]], [])", + "(4, [[1, 0], [2, 0], [3, 0]], [0, 1, 2, 3])", + "(5, [[1, 0], [2, 1], [3, 2], [4, 3], [0, 4]], [])", + "(7, [[1, 0], [2, 0], [3, 1], [4, 1], [5, 2], [6, 2]], [0, 1, 2, 3, 4, 5, 6])" + ] + }, "body": " result = run_find_order(Solution, num_courses, prerequisites)\n assert_find_order(result, expected)" } ] }, - "playground_imports": "from helpers import run_find_order, assert_find_order\nfrom solution import Solution", "playground_setup": "# Example test case\nnum_courses = 4\nprerequisites = [[1, 0], [2, 0], [3, 1], [3, 2]]\nexpected = [0, 2, 1, 3]", "playground_run": "result = run_find_order(Solution, num_courses, prerequisites)\nresult", diff --git a/leetcode_py/cli/resources/leetcode/json/problems/daily_temperatures.json b/leetcode_py/cli/resources/leetcode/json/problems/daily_temperatures.json index 6dc3945..1f91918 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/daily_temperatures.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/daily_temperatures.json @@ -5,15 +5,21 @@ "problem_title": "Daily Temperatures", "difficulty": "Medium", "topics": "Array, Stack, Monotonic Stack", - "_tags": { "list": [] }, + "_tags": { + "list": [] + }, "readme_description": "Given an array of integers `temperatures` represents the daily temperatures, return an array `answer` such that `answer[i]` is the number of days you have to wait after the `ith` day to get a warmer temperature. If there is no future day for which this is possible, keep `answer[i] == 0` instead.", "_readme_examples": { "list": [ { "content": "```\nInput: temperatures = [73,74,75,71,69,72,76,73]\nOutput: [1,1,4,2,1,1,0,0]\n```\n**Explanation:**\n- For input `[73,74,75,71,69,72,76,73]`, the output should be `[1,1,4,2,1,1,0,0]`.\n- For example, the first temperature is 73. The next warmer temperature is 74, which is 1 day later, so we put 1.\n- The second temperature is 74. The next warmer temperature is 75, which is 1 day later, so we put 1.\n- The third temperature is 75. The next warmer temperature is 76, which is 4 days later, so we put 4." }, - { "content": "```\nInput: temperatures = [30,40,50,60]\nOutput: [1,1,1,0]\n```" }, - { "content": "```\nInput: temperatures = [30,60,90]\nOutput: [1,1,0]\n```" } + { + "content": "```\nInput: temperatures = [30,40,50,60]\nOutput: [1,1,1,0]\n```" + }, + { + "content": "```\nInput: temperatures = [30,60,90]\nOutput: [1,1,0]\n```" + } ] }, "readme_constraints": "- `1 <= temperatures.length <= 10^5`\n- `30 <= temperatures[i] <= 100`", @@ -43,7 +49,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -51,7 +63,45 @@ "name": "test_daily_temperatures", "signature": "(self, temperatures: list[int], expected: list[int])", "parametrize": "temperatures, expected", - "test_cases": "[([73,74,75,71,69,72,76,73], [1,1,4,2,1,1,0,0]), ([30,40,50,60], [1,1,1,0]), ([30,60,90], [1,1,0]), ([89,62,70,58,47,47,46,76,100,70], [8,1,5,4,3,2,1,1,0,0]), ([55,38,53,81,61,93,97,32,43,78], [3,1,1,2,1,1,0,1,1,0]), ([34,80,80,34,34,80,80,80,80,34], [1,0,0,2,1,0,0,0,0,0]), ([73], [0]), ([100], [0]), ([30,31,32,33,34], [1,1,1,1,0]), ([90,80,70,60,50], [0,0,0,0,0]), ([50,50,50,50], [0,0,0,0]), ([30,100,30,100], [1,0,1,0]), ([75,71,69,72,76], [4,2,1,1,0]), ([40,35,32,37,50], [4,2,1,1,0]), ([30,40,50,60,70,80,90,100], [1,1,1,1,1,1,1,0]), ([30,30], [0,0]), ([100,100], [0,0]), ([30,100], [1,0]), ([100,30], [0,0]), ([30,31,100], [1,1,0]), ([30,99,100], [1,1,0]), ([50,40,60,30,70], [2,1,2,1,0]), ([60,50,70,40,80], [2,1,2,1,0]), ([40,50,60,50,40], [1,1,0,0,0]), ([30,40,50,40,30], [1,1,0,0,0]), ([60,50,40,50,60], [0,3,1,1,0]), ([70,60,50,60,70], [0,3,1,1,0]), ([45,50,40,60,55,65], [1,2,1,2,1,0]), ([35,45,30,50,40,60], [1,2,1,2,1,0]), ([30,31,32,33,34,35,36,37,38,39], [1,1,1,1,1,1,1,1,1,0]), ([50,49,48,47,46,45,44,43,42,41], [0,0,0,0,0,0,0,0,0,0]), ([40,40,50,50,60,60], [2,1,2,1,0,0]), ([60,60,50,50,40,40], [0,0,0,0,0,0]), ([30,31,30,32], [1,2,1,0]), ([99,100,99,100], [1,0,1,0])]", + "test_cases": { + "list": [ + "([73,74,75,71,69,72,76,73], [1,1,4,2,1,1,0,0])", + "([30,40,50,60], [1,1,1,0])", + "([30,60,90], [1,1,0])", + "([89,62,70,58,47,47,46,76,100,70], [8,1,5,4,3,2,1,1,0,0])", + "([55,38,53,81,61,93,97,32,43,78], [3,1,1,2,1,1,0,1,1,0])", + "([34,80,80,34,34,80,80,80,80,34], [1,0,0,2,1,0,0,0,0,0])", + "([73], [0])", + "([100], [0])", + "([30,31,32,33,34], [1,1,1,1,0])", + "([90,80,70,60,50], [0,0,0,0,0])", + "([50,50,50,50], [0,0,0,0])", + "([30,100,30,100], [1,0,1,0])", + "([75,71,69,72,76], [4,2,1,1,0])", + "([40,35,32,37,50], [4,2,1,1,0])", + "([30,40,50,60,70,80,90,100], [1,1,1,1,1,1,1,0])", + "([30,30], [0,0])", + "([100,100], [0,0])", + "([30,100], [1,0])", + "([100,30], [0,0])", + "([30,31,100], [1,1,0])", + "([30,99,100], [1,1,0])", + "([50,40,60,30,70], [2,1,2,1,0])", + "([60,50,70,40,80], [2,1,2,1,0])", + "([40,50,60,50,40], [1,1,0,0,0])", + "([30,40,50,40,30], [1,1,0,0,0])", + "([60,50,40,50,60], [0,3,1,1,0])", + "([70,60,50,60,70], [0,3,1,1,0])", + "([45,50,40,60,55,65], [1,2,1,2,1,0])", + "([35,45,30,50,40,60], [1,2,1,2,1,0])", + "([30,31,32,33,34,35,36,37,38,39], [1,1,1,1,1,1,1,1,1,0])", + "([50,49,48,47,46,45,44,43,42,41], [0,0,0,0,0,0,0,0,0,0])", + "([40,40,50,50,60,60], [2,1,2,1,0,0])", + "([60,60,50,50,40,40], [0,0,0,0,0,0])", + "([30,31,30,32], [1,2,1,0])", + "([99,100,99,100], [1,0,1,0])" + ] + }, "body": " result = run_daily_temperatures(Solution, temperatures)\n assert_daily_temperatures(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/decode_string.json b/leetcode_py/cli/resources/leetcode/json/problems/decode_string.json index f87666c..13a3c38 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/decode_string.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/decode_string.json @@ -5,13 +5,21 @@ "problem_title": "Decode String", "difficulty": "Medium", "topics": "String, Stack, Recursion", - "_tags": { "list": ["grind"] }, + "_tags": { + "list": ["grind"] + }, "readme_description": "Given an encoded string, return its decoded string.\n\nThe encoding rule is: `k[encoded_string]`, where the `encoded_string` inside the square brackets is being repeated exactly `k` times. Note that `k` is guaranteed to be a positive integer.\n\nYou may assume that the input string is always valid; there are no extra white spaces, square brackets are well-formed, etc. Furthermore, you may assume that the original data does not contain any digits and that digits are only for those repeat numbers, `k`. For example, there will not be input like `3a` or `2[4]`.\n\nThe test cases are generated so that the length of the output will never exceed 10^5.", "_readme_examples": { "list": [ - { "content": "```\nInput: s = \"3[a]2[bc]\"\nOutput: \"aaabcbc\"\n```" }, - { "content": "```\nInput: s = \"3[a2[c]]\"\nOutput: \"accaccacc\"\n```" }, - { "content": "```\nInput: s = \"2[abc]3[cd]ef\"\nOutput: \"abcabccdcdcdef\"\n```" } + { + "content": "```\nInput: s = \"3[a]2[bc]\"\nOutput: \"aaabcbc\"\n```" + }, + { + "content": "```\nInput: s = \"3[a2[c]]\"\nOutput: \"accaccacc\"\n```" + }, + { + "content": "```\nInput: s = \"2[abc]3[cd]ef\"\nOutput: \"abcabccdcdcdef\"\n```" + } ] }, "readme_constraints": "- 1 <= s.length <= 30\n- s consists of lowercase English letters, digits, and square brackets '[]'\n- s is guaranteed to be a valid input\n- All the integers in s are in the range [1, 300]", @@ -41,7 +49,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -49,7 +63,25 @@ "name": "test_decode_string", "signature": "(self, s: str, expected: str)", "parametrize": "s, expected", - "test_cases": "[('3[a]2[bc]', 'aaabcbc'), ('3[a2[c]]', 'accaccacc'), ('2[abc]3[cd]ef', 'abcabccdcdcdef'), ('abc', 'abc'), ('2[a]', 'aa'), ('10[a]', 'aaaaaaaaaa'), ('2[b3[a]]', 'baaabaaa'), ('3[a]2[b2[c]]', 'aaabccbcc'), ('100[leetcode]', 'leetcode' * 100), ('2[2[y]pq4[2[jk]e1[f]]]ef', 'yypqjkjkefjkjkefjkjkefjkjkefyypqjkjkefjkjkefjkjkefjkjkefef'), ('', ''), ('a', 'a'), ('2[3[a]b]', 'aaabaaab'), ('3[2[ad]3[pf]]xyz', 'adadpfpfpfadadpfpfpfadadpfpfpfxyz'), ('sd2[f2[e]g]i', 'sdfeegfeegi')]", + "test_cases": { + "list": [ + "('3[a]2[bc]', 'aaabcbc')", + "('3[a2[c]]', 'accaccacc')", + "('2[abc]3[cd]ef', 'abcabccdcdcdef')", + "('abc', 'abc')", + "('2[a]', 'aa')", + "('10[a]', 'aaaaaaaaaa')", + "('2[b3[a]]', 'baaabaaa')", + "('3[a]2[b2[c]]', 'aaabccbcc')", + "('100[leetcode]', 'leetcode' * 100)", + "('2[2[y]pq4[2[jk]e1[f]]]ef', 'yypqjkjkefjkjkefjkjkefjkjkefyypqjkjkefjkjkefjkjkefjkjkefef')", + "('', '')", + "('a', 'a')", + "('2[3[a]b]', 'aaabaaab')", + "('3[2[ad]3[pf]]xyz', 'adadpfpfpfadadpfpfpfadadpfpfpfxyz')", + "('sd2[f2[e]g]i', 'sdfeegfeegi')" + ] + }, "body": " result = run_decode_string(Solution, s)\n assert_decode_string(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/decode_ways.json b/leetcode_py/cli/resources/leetcode/json/problems/decode_ways.json index 691a4b6..6f40d37 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/decode_ways.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/decode_ways.json @@ -5,7 +5,9 @@ "problem_title": "Decode Ways", "difficulty": "Medium", "topics": "String, Dynamic Programming", - "_tags": { "list": ["blind-75"] }, + "_tags": { + "list": ["blind-75"] + }, "readme_description": "You have intercepted a secret message encoded as a string of numbers. The message is decoded via the mapping: `\"1\" -> 'A', \"2\" -> 'B', ..., \"26\" -> 'Z'`. Given a string `s` containing only digits, return the number of ways to decode it. Return `0` if it cannot be decoded.", "_readme_examples": { "list": [ @@ -47,7 +49,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -55,7 +63,23 @@ "name": "test_num_decodings", "signature": "(self, s: str, expected: int)", "parametrize": "s, expected", - "test_cases": "[('12', 2), ('226', 3), ('06', 0), ('0', 0), ('10', 1), ('27', 1), ('101', 1), ('100', 0), ('110', 1), ('2101', 1), ('2611055971756562', 4), ('1', 1), ('30', 0)]", + "test_cases": { + "list": [ + "('12', 2)", + "('226', 3)", + "('06', 0)", + "('0', 0)", + "('10', 1)", + "('27', 1)", + "('101', 1)", + "('100', 0)", + "('110', 1)", + "('2101', 1)", + "('2611055971756562', 4)", + "('1', 1)", + "('30', 0)" + ] + }, "body": " result = run_num_decodings(Solution, s)\n assert_num_decodings(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/design_add_and_search_words_data_structure.json b/leetcode_py/cli/resources/leetcode/json/problems/design_add_and_search_words_data_structure.json index 3841663..4196b29 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/design_add_and_search_words_data_structure.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/design_add_and_search_words_data_structure.json @@ -5,10 +5,10 @@ "problem_title": "Design Add and Search Words Data Structure", "difficulty": "Medium", "topics": "String, Depth-First Search, Design, Trie", - "_tags": { "list": ["grind"] }, - + "_tags": { + "list": ["grind"] + }, "readme_description": "Design a data structure that supports adding new words and finding if a string matches any previously added string.\n\nImplement the `WordDictionary` class:\n\n- `WordDictionary()` Initializes the object.\n- `void addWord(word)` Adds `word` to the data structure, it can be matched later.\n- `bool search(word)` Returns `true` if there is any string in the data structure that matches `word` or `false` otherwise. `word` may contain dots `'.'` where dots can be matched with any letter.", - "_readme_examples": { "list": [ { @@ -16,9 +16,7 @@ } ] }, - "readme_constraints": "- `1 <= word.length <= 25`\n- `word` in `addWord` consists of lowercase English letters.\n- `word` in `search` consist of `'.'` or lowercase English letters.\n- There will be at most `2` dots in `word` for `search` queries.\n- At most `10^4` calls will be made to `addWord` and `search`.", - "helpers_imports": "from typing import Any", "helpers_content": "", "helpers_run_name": "word_dictionary", @@ -27,16 +25,13 @@ "helpers_assert_name": "word_dictionary", "helpers_assert_signature": "(result: list[bool | None], expected: list[bool | None]) -> bool", "helpers_assert_body": " assert result == expected\n return True", - "solution_imports": "", "solution_contents": "", "solution_class_content": "", - "test_imports": "import pytest\nfrom leetcode_py import logged_test\nfrom .helpers import assert_word_dictionary, run_word_dictionary\nfrom .solution import WordDictionary", "test_content": "", "test_class_name": "DesignAddAndSearchWordsDataStructure", "test_class_content": "", - "_solution_methods": { "list": [ { @@ -56,23 +51,36 @@ } ] }, - "_test_helper_methods": { "list": [] }, - "_test_methods": { "list": [ { "name": "test_word_dictionary", "signature": "(self, operations: list[str], inputs: list[list[str]], expected: list[bool | None])", "parametrize": "operations, inputs, expected", - "test_cases": "[(['WordDictionary', 'addWord', 'addWord', 'addWord', 'search', 'search', 'search', 'search'], [[], ['bad'], ['dad'], ['mad'], ['pad'], ['bad'], ['.ad'], ['b..']], [None, None, None, None, False, True, True, True]), (['WordDictionary', 'addWord', 'search', 'search', 'search'], [[], ['a'], ['a'], ['.'], ['aa']], [None, None, True, True, False]), (['WordDictionary', 'addWord', 'addWord', 'search', 'search', 'search'], [[], ['at'], ['and'], ['an'], ['.at'], ['an.']], [None, None, None, False, False, True]), (['WordDictionary', 'addWord', 'addWord', 'search', 'search'], [[], ['word'], ['world'], ['word'], ['wor.']], [None, None, None, True, True]), (['WordDictionary', 'addWord', 'search', 'search'], [[], ['test'], ['test'], ['t..t']], [None, None, True, True]), (['WordDictionary', 'addWord', 'addWord', 'search', 'search', 'search'], [[], ['a'], ['b'], ['a'], ['.'], ['c']], [None, None, None, True, True, False]), (['WordDictionary', 'addWord', 'addWord', 'search', 'search', 'search'], [[], ['abc'], ['def'], ['...'], ['a..'], ['..f']], [None, None, None, True, True, True]), (['WordDictionary', 'addWord', 'addWord', 'search', 'search', 'search'], [[], ['programming'], ['algorithm'], ['prog.......'], ['algo.....'], ['........ing']], [None, None, None, True, True, True]), (['WordDictionary', 'addWord', 'addWord', 'search', 'search'], [[], ['x'], ['xy'], ['.'], ['..']], [None, None, None, True, True]), (['WordDictionary', 'addWord', 'addWord', 'search', 'search', 'search'], [[], ['hello'], ['world'], ['hi'], ['word'], ['......']], [None, None, None, False, False, False]), (['WordDictionary', 'addWord', 'addWord', 'addWord', 'search', 'search', 'search', 'search'], [[], ['cat'], ['car'], ['card'], ['c..'], ['ca.'], ['c..d'], ['.....']], [None, None, None, None, True, True, True, False]), (['WordDictionary', 'addWord', 'addWord', 'addWord', 'search', 'search', 'search'], [[], ['run'], ['runner'], ['running'], ['run'], ['run...'], ['run.....']], [None, None, None, None, True, True, False]), (['WordDictionary', 'addWord', 'addWord', 'search', 'search', 'search'], [[], ['abc'], ['xyz'], ['...'], ['..'], ['....']], [None, None, None, True, False, False])]", + "test_cases": { + "list": [ + "(['WordDictionary', 'addWord', 'addWord', 'addWord', 'search', 'search', 'search', 'search'], [[], ['bad'], ['dad'], ['mad'], ['pad'], ['bad'], ['.ad'], ['b..']], [None, None, None, None, False, True, True, True])", + "(['WordDictionary', 'addWord', 'search', 'search', 'search'], [[], ['a'], ['a'], ['.'], ['aa']], [None, None, True, True, False])", + "(['WordDictionary', 'addWord', 'addWord', 'search', 'search', 'search'], [[], ['at'], ['and'], ['an'], ['.at'], ['an.']], [None, None, None, False, False, True])", + "(['WordDictionary', 'addWord', 'addWord', 'search', 'search'], [[], ['word'], ['world'], ['word'], ['wor.']], [None, None, None, True, True])", + "(['WordDictionary', 'addWord', 'search', 'search'], [[], ['test'], ['test'], ['t..t']], [None, None, True, True])", + "(['WordDictionary', 'addWord', 'addWord', 'search', 'search', 'search'], [[], ['a'], ['b'], ['a'], ['.'], ['c']], [None, None, None, True, True, False])", + "(['WordDictionary', 'addWord', 'addWord', 'search', 'search', 'search'], [[], ['abc'], ['def'], ['...'], ['a..'], ['..f']], [None, None, None, True, True, True])", + "(['WordDictionary', 'addWord', 'addWord', 'search', 'search', 'search'], [[], ['programming'], ['algorithm'], ['prog.......'], ['algo.....'], ['........ing']], [None, None, None, True, True, True])", + "(['WordDictionary', 'addWord', 'addWord', 'search', 'search'], [[], ['x'], ['xy'], ['.'], ['..']], [None, None, None, True, True])", + "(['WordDictionary', 'addWord', 'addWord', 'search', 'search', 'search'], [[], ['hello'], ['world'], ['hi'], ['word'], ['......']], [None, None, None, False, False, False])", + "(['WordDictionary', 'addWord', 'addWord', 'addWord', 'search', 'search', 'search', 'search'], [[], ['cat'], ['car'], ['card'], ['c..'], ['ca.'], ['c..d'], ['.....']], [None, None, None, None, True, True, True, False])", + "(['WordDictionary', 'addWord', 'addWord', 'addWord', 'search', 'search', 'search'], [[], ['run'], ['runner'], ['running'], ['run'], ['run...'], ['run.....']], [None, None, None, None, True, True, False])", + "(['WordDictionary', 'addWord', 'addWord', 'search', 'search', 'search'], [[], ['abc'], ['xyz'], ['...'], ['..'], ['....']], [None, None, None, True, False, False])" + ] + }, "body": " result = run_word_dictionary(WordDictionary, operations, inputs)\n assert_word_dictionary(result, expected)" } ] }, - "playground_imports": "from helpers import run_word_dictionary, assert_word_dictionary\nfrom solution import WordDictionary", "playground_setup": "# Example test case\noperations = ['WordDictionary', 'addWord', 'addWord', 'addWord', 'search', 'search', 'search', 'search']\ninputs = [[], ['bad'], ['dad'], ['mad'], ['pad'], ['bad'], ['.ad'], ['b..']]\nexpected = [None, None, None, None, False, True, True, True]", "playground_run": "result = run_word_dictionary(WordDictionary, operations, inputs)\nresult", diff --git a/leetcode_py/cli/resources/leetcode/json/problems/design_in_memory_file_system.json b/leetcode_py/cli/resources/leetcode/json/problems/design_in_memory_file_system.json index c6e9c8c..1c4bd9b 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/design_in_memory_file_system.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/design_in_memory_file_system.json @@ -5,7 +5,9 @@ "problem_title": "Design In-Memory File System", "difficulty": "Hard", "topics": "Design, Trie, Hash Table, String", - "_tags": { "list": ["grind"] }, + "_tags": { + "list": ["grind"] + }, "readme_description": "Design an in-memory file system to simulate the following functions:\n\n`ls`: Given a path in string format. If it is a file path, return a list that only contains this file's name. If it is a directory path, return the list of file and directory names **in this directory**. Your output (file and directory names together) should in **lexicographic order**.\n\n`mkdir`: Given a **directory path** that does not exist, you should make a new directory according to the path. If the middle directories in the path don't exist either, you should create them as well. This function has void return type.\n\n`addContentToFile`: Given a **file path** and **file content** in string format. If the file doesn't exist, you need to create that file containing given content. If the file already exists, you need to **append** given content to original content. This function has void return type.\n\n`readContentFromFile`: Given a **file path**, return its **content** in string format.", "_readme_examples": { "list": [ @@ -69,7 +71,22 @@ "name": "test_file_system", "signature": "(self, operations: list[str], inputs: list[list], expected: list[str | list[str] | None])", "parametrize": "operations, inputs, expected", - "test_cases": "[(['FileSystem', 'ls', 'mkdir', 'addContentToFile', 'ls', 'readContentFromFile'], [[], ['/'], ['/a/b/c'], ['/a/b/c/d', 'hello'], ['/'], ['/a/b/c/d']], [None, [], None, None, ['a'], 'hello']), (['FileSystem', 'ls', 'mkdir', 'ls', 'mkdir', 'ls'], [[], ['/'], ['/a'], ['/'], ['/a/b'], ['/']], [None, [], None, ['a'], None, ['a']]), (['FileSystem', 'mkdir', 'addContentToFile', 'ls', 'readContentFromFile'], [[], ['/x/y'], ['/x/y/z', 'content'], ['/x/y'], ['/x/y/z']], [None, None, None, ['z'], 'content']), (['FileSystem', 'addContentToFile', 'readContentFromFile', 'addContentToFile', 'readContentFromFile'], [[], ['/file', 'hello'], ['/file'], ['/file', ' world'], ['/file']], [None, None, 'hello', None, 'hello world']), (['FileSystem', 'mkdir', 'mkdir', 'ls', 'addContentToFile', 'ls'], [[], ['/a'], ['/a/b'], ['/a'], ['/a/file', 'test'], ['/a']], [None, None, None, ['b'], None, ['b', 'file']]), (['FileSystem', 'ls'], [[], ['/']], [None, []]), (['FileSystem', 'mkdir', 'ls', 'mkdir', 'ls'], [[], ['/dir1'], ['/'], ['/dir2'], ['/']], [None, None, ['dir1'], None, ['dir1', 'dir2']]), (['FileSystem', 'addContentToFile', 'ls', 'readContentFromFile'], [[], ['/root/file', 'data'], ['/root'], ['/root/file']], [None, None, ['file'], 'data']), (['FileSystem', 'mkdir', 'addContentToFile', 'ls', 'readContentFromFile'], [[], ['/folder'], ['/folder/doc', 'text'], ['/folder'], ['/folder/doc']], [None, None, None, ['doc'], 'text']), (['FileSystem', 'addContentToFile', 'addContentToFile', 'readContentFromFile'], [[], ['/log', 'line1'], ['/log', 'line2'], ['/log']], [None, None, None, 'line1line2']), (['FileSystem', 'mkdir', 'mkdir', 'mkdir', 'ls'], [[], ['/a/b/c'], ['/a/b/d'], ['/a/e'], ['/a']], [None, None, None, None, ['b', 'e']]), (['FileSystem', 'mkdir', 'addContentToFile', 'addContentToFile', 'ls', 'readContentFromFile'], [[], ['/docs'], ['/docs/readme', 'intro'], ['/docs/config', 'settings'], ['/docs'], ['/docs/readme']], [None, None, None, None, ['config', 'readme'], 'intro'])]", + "test_cases": { + "list": [ + "(['FileSystem', 'ls', 'mkdir', 'addContentToFile', 'ls', 'readContentFromFile'], [[], ['/'], ['/a/b/c'], ['/a/b/c/d', 'hello'], ['/'], ['/a/b/c/d']], [None, [], None, None, ['a'], 'hello'])", + "(['FileSystem', 'ls', 'mkdir', 'ls', 'mkdir', 'ls'], [[], ['/'], ['/a'], ['/'], ['/a/b'], ['/']], [None, [], None, ['a'], None, ['a']])", + "(['FileSystem', 'mkdir', 'addContentToFile', 'ls', 'readContentFromFile'], [[], ['/x/y'], ['/x/y/z', 'content'], ['/x/y'], ['/x/y/z']], [None, None, None, ['z'], 'content'])", + "(['FileSystem', 'addContentToFile', 'readContentFromFile', 'addContentToFile', 'readContentFromFile'], [[], ['/file', 'hello'], ['/file'], ['/file', ' world'], ['/file']], [None, None, 'hello', None, 'hello world'])", + "(['FileSystem', 'mkdir', 'mkdir', 'ls', 'addContentToFile', 'ls'], [[], ['/a'], ['/a/b'], ['/a'], ['/a/file', 'test'], ['/a']], [None, None, None, ['b'], None, ['b', 'file']])", + "(['FileSystem', 'ls'], [[], ['/']], [None, []])", + "(['FileSystem', 'mkdir', 'ls', 'mkdir', 'ls'], [[], ['/dir1'], ['/'], ['/dir2'], ['/']], [None, None, ['dir1'], None, ['dir1', 'dir2']])", + "(['FileSystem', 'addContentToFile', 'ls', 'readContentFromFile'], [[], ['/root/file', 'data'], ['/root'], ['/root/file']], [None, None, ['file'], 'data'])", + "(['FileSystem', 'mkdir', 'addContentToFile', 'ls', 'readContentFromFile'], [[], ['/folder'], ['/folder/doc', 'text'], ['/folder'], ['/folder/doc']], [None, None, None, ['doc'], 'text'])", + "(['FileSystem', 'addContentToFile', 'addContentToFile', 'readContentFromFile'], [[], ['/log', 'line1'], ['/log', 'line2'], ['/log']], [None, None, None, 'line1line2'])", + "(['FileSystem', 'mkdir', 'mkdir', 'mkdir', 'ls'], [[], ['/a/b/c'], ['/a/b/d'], ['/a/e'], ['/a']], [None, None, None, None, ['b', 'e']])", + "(['FileSystem', 'mkdir', 'addContentToFile', 'addContentToFile', 'ls', 'readContentFromFile'], [[], ['/docs'], ['/docs/readme', 'intro'], ['/docs/config', 'settings'], ['/docs'], ['/docs/readme']], [None, None, None, None, ['config', 'readme'], 'intro'])" + ] + }, "body": " result, _ = run_file_system(FileSystem, operations, inputs)\n assert_file_system(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/diagonal_traverse.json b/leetcode_py/cli/resources/leetcode/json/problems/diagonal_traverse.json index 6a06a56..768624d 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/diagonal_traverse.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/diagonal_traverse.json @@ -5,14 +5,18 @@ "problem_title": "Diagonal Traverse", "difficulty": "Medium", "topics": "Array, Matrix, Simulation", - "_tags": { "list": [] }, + "_tags": { + "list": [] + }, "readme_description": "Given an `m x n` matrix `mat`, return *an array of all the elements of the array in a diagonal order*.", "_readme_examples": { "list": [ { "content": "![Diagonal Traverse](https://assets.leetcode.com/uploads/2021/04/10/diag1-grid.jpg)\n\n```\nInput: mat = [[1,2,3],[4,5,6],[7,8,9]]\nOutput: [1,2,4,7,5,3,6,8,9]\n```" }, - { "content": "```\nInput: mat = [[1,2],[3,4]]\nOutput: [1,2,3,4]\n```" } + { + "content": "```\nInput: mat = [[1,2],[3,4]]\nOutput: [1,2,3,4]\n```" + } ] }, "readme_constraints": "- `m == mat.length`\n- `n == mat[i].length`\n- `1 <= m, n <= 10^4`\n- `1 <= m * n <= 10^4`\n- `-10^5 <= mat[i][j] <= 10^5`", @@ -42,7 +46,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -50,7 +60,22 @@ "name": "test_find_diagonal_order", "signature": "(self, mat: list[list[int]], expected: list[int])", "parametrize": "mat, expected", - "test_cases": "[([[1, 2, 3], [4, 5, 6], [7, 8, 9]], [1, 2, 4, 7, 5, 3, 6, 8, 9]), ([[1, 2], [3, 4]], [1, 2, 3, 4]), ([[1]], [1]), ([[1, 2, 3]], [1, 2, 3]), ([[1], [2], [3]], [1, 2, 3]), ([[1, 2, 3, 4], [5, 6, 7, 8]], [1, 2, 5, 6, 3, 4, 7, 8]), ([[1, 2], [3, 4], [5, 6]], [1, 2, 3, 5, 4, 6]), ([[1, 2, 3, 4, 5]], [1, 2, 3, 4, 5]), ([[1], [2], [3], [4], [5]], [1, 2, 3, 4, 5]), ([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]], [1, 2, 5, 9, 6, 3, 4, 7, 10, 11, 8, 12]), ([[-1, 0, 1], [2, -3, 4]], [-1, 0, 2, -3, 1, 4]), ([[100]], [100])]", + "test_cases": { + "list": [ + "([[1, 2, 3], [4, 5, 6], [7, 8, 9]], [1, 2, 4, 7, 5, 3, 6, 8, 9])", + "([[1, 2], [3, 4]], [1, 2, 3, 4])", + "([[1]], [1])", + "([[1, 2, 3]], [1, 2, 3])", + "([[1], [2], [3]], [1, 2, 3])", + "([[1, 2, 3, 4], [5, 6, 7, 8]], [1, 2, 5, 6, 3, 4, 7, 8])", + "([[1, 2], [3, 4], [5, 6]], [1, 2, 3, 5, 4, 6])", + "([[1, 2, 3, 4, 5]], [1, 2, 3, 4, 5])", + "([[1], [2], [3], [4], [5]], [1, 2, 3, 4, 5])", + "([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]], [1, 2, 5, 9, 6, 3, 4, 7, 10, 11, 8, 12])", + "([[-1, 0, 1], [2, -3, 4]], [-1, 0, 2, -3, 1, 4])", + "([[100]], [100])" + ] + }, "body": " result = run_find_diagonal_order(Solution, mat)\n assert_find_diagonal_order(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/diameter_of_binary_tree.json b/leetcode_py/cli/resources/leetcode/json/problems/diameter_of_binary_tree.json index 2415601..0e0b234 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/diameter_of_binary_tree.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/diameter_of_binary_tree.json @@ -5,14 +5,18 @@ "problem_title": "Diameter of Binary Tree", "difficulty": "Easy", "topics": "Tree, Depth-First Search, Binary Tree", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "Given the `root` of a binary tree, return the length of the **diameter** of the tree.\n\nThe **diameter** of a binary tree is the **length** of the longest path between any two nodes in a tree. This path may or may not pass through the `root`.\n\nThe **length** of a path between two nodes is represented by the number of edges between them.", "_readme_examples": { "list": [ { "content": "![Example 1](https://assets.leetcode.com/uploads/2021/03/06/diamtree.jpg)\n\n```\nInput: root = [1,2,3,4,5]\nOutput: 3\n```\n**Explanation:** 3 is the length of the path [4,2,1,3] or [5,2,1,3]." }, - { "content": "```\nInput: root = [1,2]\nOutput: 1\n```" } + { + "content": "```\nInput: root = [1,2]\nOutput: 1\n```" + } ] }, "readme_constraints": "- The number of nodes in the tree is in the range [1, 10^4].\n- -100 <= Node.val <= 100", @@ -42,7 +46,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -50,7 +60,22 @@ "name": "test_diameter_of_binary_tree", "signature": "(self, root_list: list[int | None], expected: int)", "parametrize": "root_list, expected", - "test_cases": "[([1, 2, 3, 4, 5], 3), ([1, 2], 1), ([], 0), ([1], 0), ([1, 2, 3], 2), ([1, None, 2], 1), ([1, 2, 3, 4, 5, None, None, 6, 7], 4), ([4, 2, 6, 1, 3, 5, 7], 4), ([1, 2, None, 3, None, 4], 3), ([1, 2, 3, None, None, 4, 5, None, None, 6, 7], 4), ([10, 5, 15, 3, 7, 12, 20], 4), ([1, None, 2, None, 3, None, 4], 3)]", + "test_cases": { + "list": [ + "([1, 2, 3, 4, 5], 3)", + "([1, 2], 1)", + "([], 0)", + "([1], 0)", + "([1, 2, 3], 2)", + "([1, None, 2], 1)", + "([1, 2, 3, 4, 5, None, None, 6, 7], 4)", + "([4, 2, 6, 1, 3, 5, 7], 4)", + "([1, 2, None, 3, None, 4], 3)", + "([1, 2, 3, None, None, 4, 5, None, None, 6, 7], 4)", + "([10, 5, 15, 3, 7, 12, 20], 4)", + "([1, None, 2, None, 3, None, 4], 3)" + ] + }, "body": " result = run_diameter_of_binary_tree(Solution, root_list)\n assert_diameter_of_binary_tree(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/evaluate_reverse_polish_notation.json b/leetcode_py/cli/resources/leetcode/json/problems/evaluate_reverse_polish_notation.json index b2f5048..abf5627 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/evaluate_reverse_polish_notation.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/evaluate_reverse_polish_notation.json @@ -5,7 +5,9 @@ "problem_title": "Evaluate Reverse Polish Notation", "difficulty": "Medium", "topics": "Array, Math, Stack", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "You are given an array of strings `tokens` that represents an arithmetic expression in a **Reverse Polish Notation**.\n\nEvaluate the expression. Return *an integer that represents the value of the expression*.\n\n**Note that:**\n\n- The valid operators are `'+'`, `'-'`, `'*'`, and `'/'`.\n- Each operand may be an integer or another expression.\n- The division between two integers always **truncates toward zero**.\n- There will not be any division by zero.\n- The input represents a valid arithmetic expression in a reverse polish notation.\n- The answer and all the intermediate calculations can be represented in a **32-bit** integer.", "_readme_examples": { "list": [ @@ -47,7 +49,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -55,7 +63,23 @@ "name": "test_eval_rpn", "signature": "(self, tokens: list[str], expected: int)", "parametrize": "tokens, expected", - "test_cases": "[(['2', '1', '+', '3', '*'], 9), (['4', '13', '5', '/', '+'], 6), (['10', '6', '9', '3', '+', '-11', '*', '/', '*', '17', '+', '5', '+'], 22), (['3'], 3), (['15', '7', '1', '1', '+', '-', '/', '3', '*', '2', '1', '1', '+', '+', '-'], 5), (['2', '1', '+'], 3), (['2', '1', '-'], 1), (['3', '4', '*'], 12), (['8', '2', '/'], 4), (['5', '1', '2', '+', '4', '*', '+', '3', '-'], 14), (['-1', '2', '+'], 1), (['0', '3', '/'], 0), (['18', '6', '/', '3', '/'], 1)]", + "test_cases": { + "list": [ + "(['2', '1', '+', '3', '*'], 9)", + "(['4', '13', '5', '/', '+'], 6)", + "(['10', '6', '9', '3', '+', '-11', '*', '/', '*', '17', '+', '5', '+'], 22)", + "(['3'], 3)", + "(['15', '7', '1', '1', '+', '-', '/', '3', '*', '2', '1', '1', '+', '+', '-'], 5)", + "(['2', '1', '+'], 3)", + "(['2', '1', '-'], 1)", + "(['3', '4', '*'], 12)", + "(['8', '2', '/'], 4)", + "(['5', '1', '2', '+', '4', '*', '+', '3', '-'], 14)", + "(['-1', '2', '+'], 1)", + "(['0', '3', '/'], 0)", + "(['18', '6', '/', '3', '/'], 1)" + ] + }, "body": " result = run_eval_rpn(Solution, tokens)\n assert_eval_rpn(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/find_all_anagrams_in_a_string.json b/leetcode_py/cli/resources/leetcode/json/problems/find_all_anagrams_in_a_string.json index 8eba9a3..e33d9f9 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/find_all_anagrams_in_a_string.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/find_all_anagrams_in_a_string.json @@ -5,7 +5,9 @@ "problem_title": "Find All Anagrams in a String", "difficulty": "Medium", "topics": "Hash Table, String, Sliding Window", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "Given two strings `s` and `p`, return an array of all the start indices of `p`'s anagrams in `s`. You may return the answer in any order.\n\nAn **anagram** is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.", "_readme_examples": { "list": [ @@ -44,7 +46,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -52,7 +60,22 @@ "name": "test_find_anagrams", "signature": "(self, s: str, p: str, expected: list[int])", "parametrize": "s, p, expected", - "test_cases": "[('cbaebabacd', 'abc', [0, 6]), ('abab', 'ab', [0, 1, 2]), ('a', 'aa', []), ('aa', 'aa', [0]), ('abcdefg', 'xyz', []), ('aab', 'ab', [1]), ('aaab', 'ab', [2]), ('baa', 'aa', [1]), ('abacabad', 'aaab', []), ('ababacb', 'abc', [3, 4]), ('abaacbabc', 'abc', [3, 4, 6]), ('abab', 'abab', [0])]", + "test_cases": { + "list": [ + "('cbaebabacd', 'abc', [0, 6])", + "('abab', 'ab', [0, 1, 2])", + "('a', 'aa', [])", + "('aa', 'aa', [0])", + "('abcdefg', 'xyz', [])", + "('aab', 'ab', [1])", + "('aaab', 'ab', [2])", + "('baa', 'aa', [1])", + "('abacabad', 'aaab', [])", + "('ababacb', 'abc', [3, 4])", + "('abaacbabc', 'abc', [3, 4, 6])", + "('abab', 'abab', [0])" + ] + }, "body": " result = run_find_anagrams(Solution, s, p)\n assert_find_anagrams(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/find_k_closest_elements.json b/leetcode_py/cli/resources/leetcode/json/problems/find_k_closest_elements.json index bb775ed..32fb7fc 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/find_k_closest_elements.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/find_k_closest_elements.json @@ -5,12 +5,18 @@ "problem_title": "Find K Closest Elements", "difficulty": "Medium", "topics": "Array, Two Pointers, Binary Search, Sliding Window, Sorting, Heap (Priority Queue)", - "_tags": { "list": ["grind"] }, + "_tags": { + "list": ["grind"] + }, "readme_description": "Given a **sorted** integer array `arr`, two integers `k` and `x`, return the `k` closest integers to `x` in the array. The result should also be sorted in ascending order.\n\nAn integer `a` is closer to `x` than an integer `b` if:\n\n- `|a - x| < |b - x|`, or\n- `|a - x| == |b - x|` and `a < b`", "_readme_examples": { "list": [ - { "content": "```\nInput: arr = [1,2,3,4,5], k = 4, x = 3\nOutput: [1,2,3,4]\n```" }, - { "content": "```\nInput: arr = [1,1,2,3,4,5], k = 4, x = -1\nOutput: [1,1,2,3]\n```" } + { + "content": "```\nInput: arr = [1,2,3,4,5], k = 4, x = 3\nOutput: [1,2,3,4]\n```" + }, + { + "content": "```\nInput: arr = [1,1,2,3,4,5], k = 4, x = -1\nOutput: [1,1,2,3]\n```" + } ] }, "readme_constraints": "- `1 <= k <= arr.length`\n- `1 <= arr.length <= 10^4`\n- `arr` is sorted in **ascending** order.\n- `-10^4 <= arr[i], x <= 10^4`", @@ -40,7 +46,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -48,7 +60,28 @@ "name": "test_find_closest_elements", "signature": "(self, arr: list[int], k: int, x: int, expected: list[int])", "parametrize": "arr, k, x, expected", - "test_cases": "[([1, 2, 3, 4, 5], 4, 3, [1, 2, 3, 4]), ([1, 1, 2, 3, 4, 5], 4, -1, [1, 1, 2, 3]), ([1, 2, 3, 4, 5], 4, -1, [1, 2, 3, 4]), ([1, 2, 3, 4, 5], 1, 3, [3]), ([1, 2, 3, 4, 5], 2, 3, [2, 3]), ([1, 2, 3, 4, 5], 3, 3, [2, 3, 4]), ([1, 2, 3, 4, 5], 5, 3, [1, 2, 3, 4, 5]), ([0, 0, 1, 2, 3, 3, 4, 7, 7, 8], 3, 5, [3, 3, 4]), ([1, 3], 1, 2, [1]), ([1, 3], 1, 3, [3]), ([1, 3], 2, 2, [1, 3]), ([0, 1, 1, 1, 2, 3, 6, 7, 8, 9], 9, 4, [0, 1, 1, 1, 2, 3, 6, 7, 8]), ([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 5, 5, [3, 4, 5, 6, 7]), ([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 3, 1, [1, 2, 3]), ([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 3, 10, [8, 9, 10]), ([-5, -3, -1, 0, 2, 4, 6], 4, 1, [-1, 0, 2, 4]), ([10], 1, 5, [10]), ([1, 2, 4, 5, 6, 6, 8, 9], 4, 6, [4, 5, 6, 6])]", + "test_cases": { + "list": [ + "([1, 2, 3, 4, 5], 4, 3, [1, 2, 3, 4])", + "([1, 1, 2, 3, 4, 5], 4, -1, [1, 1, 2, 3])", + "([1, 2, 3, 4, 5], 4, -1, [1, 2, 3, 4])", + "([1, 2, 3, 4, 5], 1, 3, [3])", + "([1, 2, 3, 4, 5], 2, 3, [2, 3])", + "([1, 2, 3, 4, 5], 3, 3, [2, 3, 4])", + "([1, 2, 3, 4, 5], 5, 3, [1, 2, 3, 4, 5])", + "([0, 0, 1, 2, 3, 3, 4, 7, 7, 8], 3, 5, [3, 3, 4])", + "([1, 3], 1, 2, [1])", + "([1, 3], 1, 3, [3])", + "([1, 3], 2, 2, [1, 3])", + "([0, 1, 1, 1, 2, 3, 6, 7, 8, 9], 9, 4, [0, 1, 1, 1, 2, 3, 6, 7, 8])", + "([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 5, 5, [3, 4, 5, 6, 7])", + "([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 3, 1, [1, 2, 3])", + "([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 3, 10, [8, 9, 10])", + "([-5, -3, -1, 0, 2, 4, 6], 4, 1, [-1, 0, 2, 4])", + "([10], 1, 5, [10])", + "([1, 2, 4, 5, 6, 6, 8, 9], 4, 6, [4, 5, 6, 6])" + ] + }, "body": " result = run_find_closest_elements(Solution, arr, k, x)\n assert_find_closest_elements(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/find_median_from_data_stream.json b/leetcode_py/cli/resources/leetcode/json/problems/find_median_from_data_stream.json index 11b2961..a2a60d1 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/find_median_from_data_stream.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/find_median_from_data_stream.json @@ -5,7 +5,9 @@ "problem_title": "Find Median from Data Stream", "difficulty": "Hard", "topics": "Two Pointers, Design, Sorting, Heap (Priority Queue), Data Stream", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "The **median** is the middle value in an ordered integer list. If the size of the list is even, there is no middle value, and the median is the mean of the two middle values.\n\n- For example, for `arr = [2,3,4]`, the median is `3`.\n- For example, for `arr = [2,3]`, the median is `(2 + 3) / 2 = 2.5`.\n\nImplement the MedianFinder class:\n\n- `MedianFinder()` initializes the `MedianFinder` object.\n- `void addNum(int num)` adds the integer `num` from the data stream to the data structure.\n- `double findMedian()` returns the median of all elements so far. Answers within `10^-5` of the actual answer will be accepted.", "_readme_examples": { "list": [ @@ -50,14 +52,31 @@ } ] }, - "_test_helper_methods": { "list": [] }, + "_test_helper_methods": { + "list": [] + }, "_test_methods": { "list": [ { "name": "test_median_finder", "signature": "(self, operations: list[str], inputs: list[list[int]], expected: list[float | None])", "parametrize": "operations, inputs, expected", - "test_cases": "[(['MedianFinder', 'addNum', 'addNum', 'findMedian', 'addNum', 'findMedian'], [[], [1], [2], [], [3], []], [None, None, None, 1.5, None, 2.0]), (['MedianFinder', 'addNum', 'findMedian'], [[], [1], []], [None, None, 1.0]), (['MedianFinder', 'addNum', 'addNum', 'addNum', 'findMedian'], [[], [1], [1], [1], []], [None, None, None, None, 1.0]), (['MedianFinder', 'addNum', 'addNum', 'addNum', 'addNum', 'findMedian'], [[], [1], [2], [3], [4], []], [None, None, None, None, None, 2.5]), (['MedianFinder', 'addNum', 'addNum', 'findMedian', 'addNum', 'addNum', 'findMedian'], [[], [-1], [0], [], [1], [2], []], [None, None, None, -0.5, None, None, 0.5]), (['MedianFinder', 'addNum', 'addNum', 'addNum', 'addNum', 'addNum', 'findMedian'], [[], [5], [1], [3], [2], [4], []], [None, None, None, None, None, None, 3.0]), (['MedianFinder', 'addNum', 'findMedian', 'addNum', 'findMedian', 'addNum', 'findMedian'], [[], [100000], [], [-100000], [], [0], []], [None, None, 100000.0, None, 0.0, None, 0.0]), (['MedianFinder', 'addNum', 'addNum', 'addNum', 'addNum', 'addNum', 'addNum', 'addNum', 'findMedian'], [[], [10], [5], [15], [3], [7], [12], [18], []], [None, None, None, None, None, None, None, None, 10.0]), (['MedianFinder', 'addNum', 'addNum', 'addNum', 'addNum', 'addNum', 'addNum', 'findMedian'], [[], [6], [10], [2], [6], [5], [0], []], [None, None, None, None, None, None, None, 5.5]), (['MedianFinder', 'addNum', 'addNum', 'addNum', 'addNum', 'addNum', 'addNum', 'addNum', 'addNum', 'findMedian'], [[], [1], [2], [3], [4], [5], [6], [7], [8], []], [None, None, None, None, None, None, None, None, None, 4.5]), (['MedianFinder', 'addNum', 'addNum', 'addNum', 'addNum', 'addNum', 'addNum', 'addNum', 'addNum', 'addNum', 'findMedian'], [[], [9], [8], [7], [6], [5], [4], [3], [2], [1], []], [None, None, None, None, None, None, None, None, None, None, 5.0]), (['MedianFinder', 'addNum', 'addNum', 'addNum', 'addNum', 'addNum', 'findMedian'], [[], [0], [0], [0], [0], [0], []], [None, None, None, None, None, None, 0.0])]", + "test_cases": { + "list": [ + "(['MedianFinder', 'addNum', 'addNum', 'findMedian', 'addNum', 'findMedian'], [[], [1], [2], [], [3], []], [None, None, None, 1.5, None, 2.0])", + "(['MedianFinder', 'addNum', 'findMedian'], [[], [1], []], [None, None, 1.0])", + "(['MedianFinder', 'addNum', 'addNum', 'addNum', 'findMedian'], [[], [1], [1], [1], []], [None, None, None, None, 1.0])", + "(['MedianFinder', 'addNum', 'addNum', 'addNum', 'addNum', 'findMedian'], [[], [1], [2], [3], [4], []], [None, None, None, None, None, 2.5])", + "(['MedianFinder', 'addNum', 'addNum', 'findMedian', 'addNum', 'addNum', 'findMedian'], [[], [-1], [0], [], [1], [2], []], [None, None, None, -0.5, None, None, 0.5])", + "(['MedianFinder', 'addNum', 'addNum', 'addNum', 'addNum', 'addNum', 'findMedian'], [[], [5], [1], [3], [2], [4], []], [None, None, None, None, None, None, 3.0])", + "(['MedianFinder', 'addNum', 'findMedian', 'addNum', 'findMedian', 'addNum', 'findMedian'], [[], [100000], [], [-100000], [], [0], []], [None, None, 100000.0, None, 0.0, None, 0.0])", + "(['MedianFinder', 'addNum', 'addNum', 'addNum', 'addNum', 'addNum', 'addNum', 'addNum', 'findMedian'], [[], [10], [5], [15], [3], [7], [12], [18], []], [None, None, None, None, None, None, None, None, 10.0])", + "(['MedianFinder', 'addNum', 'addNum', 'addNum', 'addNum', 'addNum', 'addNum', 'findMedian'], [[], [6], [10], [2], [6], [5], [0], []], [None, None, None, None, None, None, None, 5.5])", + "(['MedianFinder', 'addNum', 'addNum', 'addNum', 'addNum', 'addNum', 'addNum', 'addNum', 'addNum', 'findMedian'], [[], [1], [2], [3], [4], [5], [6], [7], [8], []], [None, None, None, None, None, None, None, None, None, 4.5])", + "(['MedianFinder', 'addNum', 'addNum', 'addNum', 'addNum', 'addNum', 'addNum', 'addNum', 'addNum', 'addNum', 'findMedian'], [[], [9], [8], [7], [6], [5], [4], [3], [2], [1], []], [None, None, None, None, None, None, None, None, None, None, 5.0])", + "(['MedianFinder', 'addNum', 'addNum', 'addNum', 'addNum', 'addNum', 'findMedian'], [[], [0], [0], [0], [0], [0], []], [None, None, None, None, None, None, 0.0])" + ] + }, "body": " result, _ = run_median_finder(MedianFinder, operations, inputs)\n assert_median_finder(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/find_the_duplicate_number.json b/leetcode_py/cli/resources/leetcode/json/problems/find_the_duplicate_number.json index 44685dc..fdd4dd4 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/find_the_duplicate_number.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/find_the_duplicate_number.json @@ -5,13 +5,21 @@ "problem_title": "Find the Duplicate Number", "difficulty": "Medium", "topics": "Array, Two Pointers, Binary Search, Bit Manipulation", - "_tags": { "list": ["grind"] }, + "_tags": { + "list": ["grind"] + }, "readme_description": "Given an array of integers `nums` containing `n + 1` integers where each integer is in the range `[1, n]` inclusive.\n\nThere is only **one repeated number** in `nums`, return *this repeated number*.\n\nYou must solve the problem **without** modifying the array `nums` and using only constant extra space.", "_readme_examples": { "list": [ - { "content": "```\nInput: nums = [1,3,4,2,2]\nOutput: 2\n```" }, - { "content": "```\nInput: nums = [3,1,3,4,2]\nOutput: 3\n```" }, - { "content": "```\nInput: nums = [3,3,3,3,3]\nOutput: 3\n```" } + { + "content": "```\nInput: nums = [1,3,4,2,2]\nOutput: 2\n```" + }, + { + "content": "```\nInput: nums = [3,1,3,4,2]\nOutput: 3\n```" + }, + { + "content": "```\nInput: nums = [3,3,3,3,3]\nOutput: 3\n```" + } ] }, "readme_constraints": "- `1 <= n <= 10^5`\n- `nums.length == n + 1`\n- `1 <= nums[i] <= n`\n- All the integers in `nums` appear only **once** except for **precisely one integer** which appears **two or more** times.", @@ -41,7 +49,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -49,7 +63,28 @@ "name": "test_find_duplicate", "signature": "(self, nums: list[int], expected: int)", "parametrize": "nums, expected", - "test_cases": "[([1, 3, 4, 2, 2], 2), ([3, 1, 3, 4, 2], 3), ([3, 3, 3, 3, 3], 3), ([1, 1], 1), ([2, 2, 2], 2), ([1, 2, 3, 4, 4], 4), ([4, 3, 2, 1, 2], 2), ([2, 5, 9, 6, 9, 3, 8, 9, 7, 1], 9), ([1, 4, 4, 2, 4], 4), ([3, 1, 3, 4, 2], 3), ([1, 3, 4, 2, 2], 2), ([2, 1, 3, 4, 5, 6, 7, 8, 9, 9], 9), ([5, 2, 1, 3, 5, 7, 6, 4], 5), ([1, 2, 2], 2), ([1, 1, 2], 1), ([2, 1, 1], 1), ([1, 2, 3, 3], 3), ([4, 1, 2, 3, 4], 4)]", + "test_cases": { + "list": [ + "([1, 3, 4, 2, 2], 2)", + "([3, 1, 3, 4, 2], 3)", + "([3, 3, 3, 3, 3], 3)", + "([1, 1], 1)", + "([2, 2, 2], 2)", + "([1, 2, 3, 4, 4], 4)", + "([4, 3, 2, 1, 2], 2)", + "([2, 5, 9, 6, 9, 3, 8, 9, 7, 1], 9)", + "([1, 4, 4, 2, 4], 4)", + "([3, 1, 3, 4, 2], 3)", + "([1, 3, 4, 2, 2], 2)", + "([2, 1, 3, 4, 5, 6, 7, 8, 9, 9], 9)", + "([5, 2, 1, 3, 5, 7, 6, 4], 5)", + "([1, 2, 2], 2)", + "([1, 1, 2], 1)", + "([2, 1, 1], 1)", + "([1, 2, 3, 3], 3)", + "([4, 1, 2, 3, 4], 4)" + ] + }, "body": " result = run_find_duplicate(Solution, nums)\n assert_find_duplicate(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/first_bad_version.json b/leetcode_py/cli/resources/leetcode/json/problems/first_bad_version.json index d8b8699..9c22c27 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/first_bad_version.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/first_bad_version.json @@ -5,14 +5,18 @@ "problem_title": "First Bad Version", "difficulty": "Easy", "topics": "Binary Search, Interactive", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on the previous version, all the versions after a bad version are also bad.\n\nSuppose you have `n` versions `[1, 2, ..., n]` and you want to find out the first bad one, which causes all the following ones to be bad.\n\nYou are given an API `bool isBadVersion(version)` which returns whether `version` is bad. Implement a function to find the first bad version. You should minimize the number of calls to the API.", "_readme_examples": { "list": [ { "content": "```\nInput: n = 5, bad = 4\nOutput: 4\n```\n**Explanation:**\n```\ncall isBadVersion(3) -> false\ncall isBadVersion(5) -> true\ncall isBadVersion(4) -> true\n```\nThen 4 is the first bad version." }, - { "content": "```\nInput: n = 1, bad = 1\nOutput: 1\n```" } + { + "content": "```\nInput: n = 1, bad = 1\nOutput: 1\n```" + } ] }, "readme_constraints": "- 1 <= bad <= n <= 2^31 - 1", @@ -47,7 +51,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -55,7 +65,25 @@ "name": "test_first_bad_version", "signature": "(self, n: int, bad: int, expected: int)", "parametrize": "n, bad, expected", - "test_cases": "[(5, 4, 4), (1, 1, 1), (3, 1, 1), (10, 7, 7), (100, 50, 50), (2, 1, 1), (2, 2, 2), (1000, 1, 1), (1000, 999, 999), (1000, 500, 500), (20, 15, 15), (50, 25, 25), (8, 3, 3), (16, 9, 9), (200, 150, 150)]", + "test_cases": { + "list": [ + "(5, 4, 4)", + "(1, 1, 1)", + "(3, 1, 1)", + "(10, 7, 7)", + "(100, 50, 50)", + "(2, 1, 1)", + "(2, 2, 2)", + "(1000, 1, 1)", + "(1000, 999, 999)", + "(1000, 500, 500)", + "(20, 15, 15)", + "(50, 25, 25)", + "(8, 3, 3)", + "(16, 9, 9)", + "(200, 150, 150)" + ] + }, "body": " result = run_first_bad_version(Solution, n, bad)\n assert_first_bad_version(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/flood_fill.json b/leetcode_py/cli/resources/leetcode/json/problems/flood_fill.json index b63f274..f2a3b9f 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/flood_fill.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/flood_fill.json @@ -5,7 +5,9 @@ "problem_title": "Flood Fill", "difficulty": "Easy", "topics": "Array, Depth-First Search, Breadth-First Search, Matrix", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "You are given an image represented by an `m x n` grid of integers `image`, where `image[i][j]` represents the pixel value of the image. You are also given three integers `sr`, `sc`, and `color`. Your task is to perform a **flood fill** on the image starting from the pixel `image[sr][sc]`.\n\nTo perform a **flood fill**:\n\n1. Begin with the starting pixel and change its color to `color`.\n2. Perform the same process for each pixel that is **directly adjacent** (pixels that share a side with the original pixel, either horizontally or vertically) and shares the **same color** as the starting pixel.\n3. Keep **repeating** this process by checking neighboring pixels of the *updated* pixels and modifying their color if it matches the original color of the starting pixel.\n4. The process **stops** when there are **no more** adjacent pixels of the original color to update.\n\nReturn the **modified** image after performing the flood fill.", "_readme_examples": { "list": [ @@ -44,7 +46,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -52,7 +60,22 @@ "name": "test_flood_fill", "signature": "(self, image: list[list[int]], sr: int, sc: int, color: int, expected: list[list[int]])", "parametrize": "image, sr, sc, color, expected", - "test_cases": "[([[1, 1, 1], [1, 1, 0], [1, 0, 1]], 1, 1, 2, [[2, 2, 2], [2, 2, 0], [2, 0, 1]]), ([[0, 0, 0], [0, 0, 0]], 0, 0, 0, [[0, 0, 0], [0, 0, 0]]), ([[0, 0, 0], [0, 1, 1]], 1, 1, 1, [[0, 0, 0], [0, 1, 1]]), ([[1, 1, 1], [1, 1, 0], [1, 0, 1]], 1, 1, 1, [[1, 1, 1], [1, 1, 0], [1, 0, 1]]), ([[1]], 0, 0, 2, [[2]]), ([[0, 1], [1, 0]], 0, 0, 3, [[3, 1], [1, 0]]), ([[1, 1], [1, 1]], 0, 0, 2, [[2, 2], [2, 2]]), ([[0, 1, 0], [1, 0, 1], [0, 1, 0]], 1, 1, 2, [[0, 1, 0], [1, 2, 1], [0, 1, 0]]), ([[2, 2, 2], [2, 2, 0], [2, 0, 1]], 0, 0, 3, [[3, 3, 3], [3, 3, 0], [3, 0, 1]]), ([[1, 0, 1], [0, 1, 0], [1, 0, 1]], 1, 1, 5, [[1, 0, 1], [0, 5, 0], [1, 0, 1]]), ([[0, 0, 0, 0], [0, 1, 1, 0], [0, 1, 1, 0], [0, 0, 0, 0]], 1, 1, 2, [[0, 0, 0, 0], [0, 2, 2, 0], [0, 2, 2, 0], [0, 0, 0, 0]]), ([[1, 2, 3], [4, 5, 6], [7, 8, 9]], 1, 1, 0, [[1, 2, 3], [4, 0, 6], [7, 8, 9]])]", + "test_cases": { + "list": [ + "([[1, 1, 1], [1, 1, 0], [1, 0, 1]], 1, 1, 2, [[2, 2, 2], [2, 2, 0], [2, 0, 1]])", + "([[0, 0, 0], [0, 0, 0]], 0, 0, 0, [[0, 0, 0], [0, 0, 0]])", + "([[0, 0, 0], [0, 1, 1]], 1, 1, 1, [[0, 0, 0], [0, 1, 1]])", + "([[1, 1, 1], [1, 1, 0], [1, 0, 1]], 1, 1, 1, [[1, 1, 1], [1, 1, 0], [1, 0, 1]])", + "([[1]], 0, 0, 2, [[2]])", + "([[0, 1], [1, 0]], 0, 0, 3, [[3, 1], [1, 0]])", + "([[1, 1], [1, 1]], 0, 0, 2, [[2, 2], [2, 2]])", + "([[0, 1, 0], [1, 0, 1], [0, 1, 0]], 1, 1, 2, [[0, 1, 0], [1, 2, 1], [0, 1, 0]])", + "([[2, 2, 2], [2, 2, 0], [2, 0, 1]], 0, 0, 3, [[3, 3, 3], [3, 3, 0], [3, 0, 1]])", + "([[1, 0, 1], [0, 1, 0], [1, 0, 1]], 1, 1, 5, [[1, 0, 1], [0, 5, 0], [1, 0, 1]])", + "([[0, 0, 0, 0], [0, 1, 1, 0], [0, 1, 1, 0], [0, 0, 0, 0]], 1, 1, 2, [[0, 0, 0, 0], [0, 2, 2, 0], [0, 2, 2, 0], [0, 0, 0, 0]])", + "([[1, 2, 3], [4, 5, 6], [7, 8, 9]], 1, 1, 0, [[1, 2, 3], [4, 0, 6], [7, 8, 9]])" + ] + }, "body": " result = run_flood_fill(Solution, image, sr, sc, color)\n assert_flood_fill(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/gas_station.json b/leetcode_py/cli/resources/leetcode/json/problems/gas_station.json index db27dc9..38b131c 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/gas_station.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/gas_station.json @@ -42,7 +42,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -50,7 +56,22 @@ "name": "test_can_complete_circuit", "signature": "(self, gas: list[int], cost: list[int], expected: int)", "parametrize": "gas, cost, expected", - "test_cases": "[([1,2,3,4,5], [3,4,5,1,2], 3), ([2,3,4], [3,4,3], -1), ([1,2], [2,1], 1), ([5], [4], 0), ([2], [2], 0), ([1,2,3], [3,3,3], -1), ([3,1,1], [1,2,2], 0), ([5,1,2,3,4], [4,4,1,5,1], 4), ([1,2,3,4,5,5,70], [2,3,4,3,9,6,2], 6), ([4,5,2,6,5,3], [3,2,7,3,2,9], -1), ([6,1,4,3,5], [3,8,2,4,2], 2), ([2,3,4,5], [3,4,5,6], -1)]", + "test_cases": { + "list": [ + "([1,2,3,4,5], [3,4,5,1,2], 3)", + "([2,3,4], [3,4,3], -1)", + "([1,2], [2,1], 1)", + "([5], [4], 0)", + "([2], [2], 0)", + "([1,2,3], [3,3,3], -1)", + "([3,1,1], [1,2,2], 0)", + "([5,1,2,3,4], [4,4,1,5,1], 4)", + "([1,2,3,4,5,5,70], [2,3,4,3,9,6,2], 6)", + "([4,5,2,6,5,3], [3,2,7,3,2,9], -1)", + "([6,1,4,3,5], [3,8,2,4,2], 2)", + "([2,3,4,5], [3,4,5,6], -1)" + ] + }, "body": " result = run_can_complete_circuit(Solution, gas, cost)\n assert_can_complete_circuit(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/group_anagrams.json b/leetcode_py/cli/resources/leetcode/json/problems/group_anagrams.json index 16926b3..b4c315c 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/group_anagrams.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/group_anagrams.json @@ -5,22 +5,24 @@ "problem_title": "Group Anagrams", "difficulty": "Medium", "topics": "Array, Hash Table, String, Sorting", - "_tags": { "list": ["grind"] }, - + "_tags": { + "list": ["grind"] + }, "readme_description": "Given an array of strings `strs`, group the anagrams together. You can return the answer in **any order**.\n\nAn **anagram** is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.", - "_readme_examples": { "list": [ { "content": "```\nInput: strs = [\"eat\",\"tea\",\"tan\",\"ate\",\"nat\",\"bat\"]\nOutput: [[\"bat\"],[\"nat\",\"tan\"],[\"ate\",\"eat\",\"tea\"]]\nExplanation:\n- There is no string in strs that can be rearranged to form \"bat\".\n- The strings \"nat\" and \"tan\" are anagrams as they can be rearranged to form each other.\n- The strings \"ate\", \"eat\", and \"tea\" are anagrams as they can be rearranged to form each other.\n```" }, - { "content": "```\nInput: strs = [\"\"]\nOutput: [[\"\"]]\n```" }, - { "content": "```\nInput: strs = [\"a\"]\nOutput: [[\"a\"]]\n```" } + { + "content": "```\nInput: strs = [\"\"]\nOutput: [[\"\"]]\n```" + }, + { + "content": "```\nInput: strs = [\"a\"]\nOutput: [[\"a\"]]\n```" + } ] }, - "readme_constraints": "- `1 <= strs.length <= 10^4`\n- `0 <= strs[i].length <= 100`\n- `strs[i]` consists of lowercase English letters.", - "helpers_imports": "", "helpers_content": "", "helpers_run_name": "group_anagrams", @@ -29,16 +31,13 @@ "helpers_assert_name": "group_anagrams", "helpers_assert_signature": "(result: list[list[str]], expected: list[list[str]]) -> bool", "helpers_assert_body": " # Sort both result and expected for comparison since order doesn't matter\n result_sorted = [sorted(group) for group in result]\n expected_sorted = [sorted(group) for group in expected]\n result_sorted.sort()\n expected_sorted.sort()\n assert result_sorted == expected_sorted\n return True", - "solution_imports": "", "solution_contents": "", "solution_class_content": "", - "test_imports": "import pytest\nfrom leetcode_py import logged_test\nfrom .helpers import assert_group_anagrams, run_group_anagrams\nfrom .solution import Solution", "test_content": "", "test_class_name": "GroupAnagrams", "test_class_content": " def setup_method(self):\n self.solution = Solution()", - "_solution_methods": { "list": [ { @@ -48,23 +47,44 @@ } ] }, - "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, - "_test_methods": { "list": [ { "name": "test_group_anagrams", "signature": "(self, strs: list[str], expected: list[list[str]])", "parametrize": "strs, expected", - "test_cases": "[(['eat', 'tea', 'tan', 'ate', 'nat', 'bat'], [['bat'], ['nat', 'tan'], ['ate', 'eat', 'tea']]), ([''], [['']]), (['a'], [['a']]), (['abc', 'bca', 'cab', 'xyz'], [['abc', 'bca', 'cab'], ['xyz']]), (['ab', 'ba'], [['ab', 'ba']]), (['abc'], [['abc']]), (['listen', 'silent', 'hello'], [['listen', 'silent'], ['hello']]), (['aab', 'aba', 'baa'], [['aab', 'aba', 'baa']]), (['race', 'care', 'acre'], [['race', 'care', 'acre']]), (['', 'b'], [[''], ['b']]), (['a', 'aa', 'aaa'], [['a'], ['aa'], ['aaa']]), (['abc', 'def', 'ghi'], [['abc'], ['def'], ['ghi']]), (['abcd', 'dcba', 'lls', 'sll'], [['abcd', 'dcba'], ['lls', 'sll']]), (['ac', 'c'], [['ac'], ['c']]), (['huh', 'tit'], [['huh'], ['tit']])]", + "test_cases": { + "list": [ + "(['eat', 'tea', 'tan', 'ate', 'nat', 'bat'], [['bat'], ['nat', 'tan'], ['ate', 'eat', 'tea']])", + "([''], [['']])", + "(['a'], [['a']])", + "(['abc', 'bca', 'cab', 'xyz'], [['abc', 'bca', 'cab'], ['xyz']])", + "(['ab', 'ba'], [['ab', 'ba']])", + "(['abc'], [['abc']])", + "(['listen', 'silent', 'hello'], [['listen', 'silent'], ['hello']])", + "(['aab', 'aba', 'baa'], [['aab', 'aba', 'baa']])", + "(['race', 'care', 'acre'], [['race', 'care', 'acre']])", + "(['', 'b'], [[''], ['b']])", + "(['a', 'aa', 'aaa'], [['a'], ['aa'], ['aaa']])", + "(['abc', 'def', 'ghi'], [['abc'], ['def'], ['ghi']])", + "(['abcd', 'dcba', 'lls', 'sll'], [['abcd', 'dcba'], ['lls', 'sll']])", + "(['ac', 'c'], [['ac'], ['c']])", + "(['huh', 'tit'], [['huh'], ['tit']])" + ] + }, "body": " result = run_group_anagrams(Solution, strs)\n assert_group_anagrams(result, expected)" } ] }, - "playground_imports": "from helpers import run_group_anagrams, assert_group_anagrams\nfrom solution import Solution", "playground_setup": "# Example test case\nstrs = ['eat', 'tea', 'tan', 'ate', 'nat', 'bat']\nexpected = [['bat'], ['nat', 'tan'], ['ate', 'eat', 'tea']]", "playground_run": "result = run_group_anagrams(Solution, strs)\nresult", diff --git a/leetcode_py/cli/resources/leetcode/json/problems/house_robber.json b/leetcode_py/cli/resources/leetcode/json/problems/house_robber.json index 3f27e7c..e6999ba 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/house_robber.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/house_robber.json @@ -5,10 +5,10 @@ "problem_title": "House Robber", "difficulty": "Medium", "topics": "Array, Dynamic Programming", - "_tags": { "list": ["grind"] }, - + "_tags": { + "list": ["grind"] + }, "readme_description": "You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security systems connected and **it will automatically contact the police if two adjacent houses were broken into on the same night**.\n\nGiven an integer array `nums` representing the amount of money of each house, return *the maximum amount of money you can rob tonight **without alerting the police***.", - "_readme_examples": { "list": [ { @@ -19,9 +19,7 @@ } ] }, - "readme_constraints": "- `1 <= nums.length <= 100`\n- `0 <= nums[i] <= 400`", - "helpers_imports": "", "helpers_content": "", "helpers_run_name": "rob", @@ -30,16 +28,13 @@ "helpers_assert_name": "rob", "helpers_assert_signature": "(result: int, expected: int) -> bool", "helpers_assert_body": " assert result == expected\n return True", - "solution_imports": "", "solution_contents": "", "solution_class_content": "", - "test_imports": "import pytest\nfrom leetcode_py import logged_test\nfrom .helpers import assert_rob, run_rob\nfrom .solution import Solution", "test_content": "", "test_class_name": "HouseRobber", "test_class_content": " def setup_method(self):\n self.solution = Solution()", - "_solution_methods": { "list": [ { @@ -49,23 +44,44 @@ } ] }, - "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, - "_test_methods": { "list": [ { "name": "test_rob", "signature": "(self, nums: list[int], expected: int)", "parametrize": "nums, expected", - "test_cases": "[([1, 2, 3, 1], 4), ([2, 7, 9, 3, 1], 12), ([1], 1), ([2, 1], 2), ([5, 1, 3, 9], 14), ([2, 7, 9, 3, 1, 5, 8], 20), ([0, 0, 0], 0), ([5], 5), ([1, 2], 2), ([2, 1, 1, 2], 4), ([5, 5, 10, 100, 10, 5], 110), ([100, 1, 1, 100], 200), ([1, 3, 1, 3, 100], 103), ([400, 0, 400], 800), ([1, 2, 3, 4, 5], 9)]", + "test_cases": { + "list": [ + "([1, 2, 3, 1], 4)", + "([2, 7, 9, 3, 1], 12)", + "([1], 1)", + "([2, 1], 2)", + "([5, 1, 3, 9], 14)", + "([2, 7, 9, 3, 1, 5, 8], 20)", + "([0, 0, 0], 0)", + "([5], 5)", + "([1, 2], 2)", + "([2, 1, 1, 2], 4)", + "([5, 5, 10, 100, 10, 5], 110)", + "([100, 1, 1, 100], 200)", + "([1, 3, 1, 3, 100], 103)", + "([400, 0, 400], 800)", + "([1, 2, 3, 4, 5], 9)" + ] + }, "body": " result = run_rob(Solution, nums)\n assert_rob(result, expected)" } ] }, - "playground_imports": "from helpers import run_rob, assert_rob\nfrom solution import Solution", "playground_setup": "# Example test case\nnums = [2, 7, 9, 3, 1]\nexpected = 12", "playground_run": "result = run_rob(Solution, nums)\nresult", diff --git a/leetcode_py/cli/resources/leetcode/json/problems/implement_queue_using_stacks.json b/leetcode_py/cli/resources/leetcode/json/problems/implement_queue_using_stacks.json index bb35f25..f30f085 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/implement_queue_using_stacks.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/implement_queue_using_stacks.json @@ -5,7 +5,9 @@ "problem_title": "Implement Queue using Stacks", "difficulty": "Easy", "topics": "Stack, Design, Queue", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "Implement a first in first out (FIFO) queue using only two stacks. The implemented queue should support all the functions of a normal queue (`push`, `peek`, `pop`, and `empty`).\n\nImplement the `MyQueue` class:\n\n- `void push(int x)` Pushes element x to the back of the queue.\n- `int pop()` Removes the element from the front of the queue and returns it.\n- `int peek()` Returns the element at the front of the queue.\n- `boolean empty()` Returns `true` if the queue is empty, `false` otherwise.", "_readme_examples": { "list": [ @@ -60,14 +62,31 @@ } ] }, - "_test_helper_methods": { "list": [] }, + "_test_helper_methods": { + "list": [] + }, "_test_methods": { "list": [ { "name": "test_queue_operations", "signature": "(self, operations: list[str], inputs: list[list[int]], expected: list[int | None | bool])", "parametrize": "operations, inputs, expected", - "test_cases": "[(['MyQueue', 'push', 'push', 'peek', 'pop', 'empty'], [[], [1], [2], [], [], []], [None, None, None, 1, 1, False]), (['MyQueue', 'empty', 'push', 'peek', 'pop', 'empty'], [[], [], [1], [], [], []], [None, True, None, 1, 1, True]), (['MyQueue', 'push', 'push', 'push', 'pop', 'pop', 'peek', 'pop', 'empty'], [[], [1], [2], [3], [], [], [], [], []], [None, None, None, None, 1, 2, 3, 3, True]), (['MyQueue', 'push', 'peek', 'pop'], [[], [5], [], []], [None, None, 5, 5]), (['MyQueue', 'push', 'push', 'pop', 'push', 'peek'], [[], [1], [2], [], [3], []], [None, None, None, 1, None, 2]), (['MyQueue', 'empty'], [[], []], [None, True]), (['MyQueue', 'push', 'push', 'push', 'push', 'pop', 'pop', 'pop', 'pop', 'empty'], [[], [1], [2], [3], [4], [], [], [], [], []], [None, None, None, None, None, 1, 2, 3, 4, True]), (['MyQueue', 'push', 'pop', 'push', 'pop', 'empty'], [[], [7], [], [8], [], []], [None, None, 7, None, 8, True]), (['MyQueue', 'push', 'push', 'peek', 'peek', 'pop', 'peek'], [[], [9], [8], [], [], [], []], [None, None, None, 9, 9, 9, 8]), (['MyQueue', 'push', 'push', 'push', 'push', 'push', 'pop', 'pop', 'pop', 'push', 'peek'], [[], [1], [2], [3], [4], [5], [], [], [], [6], []], [None, None, None, None, None, None, 1, 2, 3, None, 4]), (['MyQueue', 'push', 'empty', 'pop', 'empty', 'push', 'empty'], [[], [1], [], [], [], [2], []], [None, None, False, 1, True, None, False]), (['MyQueue', 'push', 'push', 'push', 'pop', 'push', 'pop', 'pop', 'push', 'pop'], [[], [1], [2], [3], [], [4], [], [], [5], []], [None, None, None, None, 1, None, 2, 3, None, 4])]", + "test_cases": { + "list": [ + "(['MyQueue', 'push', 'push', 'peek', 'pop', 'empty'], [[], [1], [2], [], [], []], [None, None, None, 1, 1, False])", + "(['MyQueue', 'empty', 'push', 'peek', 'pop', 'empty'], [[], [], [1], [], [], []], [None, True, None, 1, 1, True])", + "(['MyQueue', 'push', 'push', 'push', 'pop', 'pop', 'peek', 'pop', 'empty'], [[], [1], [2], [3], [], [], [], [], []], [None, None, None, None, 1, 2, 3, 3, True])", + "(['MyQueue', 'push', 'peek', 'pop'], [[], [5], [], []], [None, None, 5, 5])", + "(['MyQueue', 'push', 'push', 'pop', 'push', 'peek'], [[], [1], [2], [], [3], []], [None, None, None, 1, None, 2])", + "(['MyQueue', 'empty'], [[], []], [None, True])", + "(['MyQueue', 'push', 'push', 'push', 'push', 'pop', 'pop', 'pop', 'pop', 'empty'], [[], [1], [2], [3], [4], [], [], [], [], []], [None, None, None, None, None, 1, 2, 3, 4, True])", + "(['MyQueue', 'push', 'pop', 'push', 'pop', 'empty'], [[], [7], [], [8], [], []], [None, None, 7, None, 8, True])", + "(['MyQueue', 'push', 'push', 'peek', 'peek', 'pop', 'peek'], [[], [9], [8], [], [], [], []], [None, None, None, 9, 9, 9, 8])", + "(['MyQueue', 'push', 'push', 'push', 'push', 'push', 'pop', 'pop', 'pop', 'push', 'peek'], [[], [1], [2], [3], [4], [5], [], [], [], [6], []], [None, None, None, None, None, None, 1, 2, 3, None, 4])", + "(['MyQueue', 'push', 'empty', 'pop', 'empty', 'push', 'empty'], [[], [1], [], [], [], [2], []], [None, None, False, 1, True, None, False])", + "(['MyQueue', 'push', 'push', 'push', 'pop', 'push', 'pop', 'pop', 'push', 'pop'], [[], [1], [2], [3], [], [4], [], [], [5], []], [None, None, None, None, 1, None, 2, 3, None, 4])" + ] + }, "body": " result, _ = run_my_queue(MyQueue, operations, inputs)\n assert_my_queue(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/implement_trie_prefix_tree.json b/leetcode_py/cli/resources/leetcode/json/problems/implement_trie_prefix_tree.json index c4af8b9..a7841d4 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/implement_trie_prefix_tree.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/implement_trie_prefix_tree.json @@ -5,7 +5,9 @@ "problem_title": "Implement Trie (Prefix Tree)", "difficulty": "Medium", "topics": "Hash Table, String, Design, Trie", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "A **trie** (pronounced as \"try\") or **prefix tree** is a tree data structure used to efficiently store and retrieve keys in a dataset of strings. There are various applications of this data structure, such as autocomplete and spellchecker.\n\nImplement the Trie class:\n\n- `Trie()` Initializes the trie object.\n- `void insert(String word)` Inserts the string `word` into the trie.\n- `boolean search(String word)` Returns `true` if the string `word` is in the trie (i.e., was inserted before), and `false` otherwise.\n- `boolean startsWith(String prefix)` Returns `true` if there is a previously inserted string `word` that has the prefix `prefix`, and `false` otherwise.", "_readme_examples": { "list": [ @@ -55,14 +57,31 @@ } ] }, - "_test_helper_methods": { "list": [] }, + "_test_helper_methods": { + "list": [] + }, "_test_methods": { "list": [ { "name": "test_trie_operations", "signature": "(self, operations: list[str], inputs: list[list[str]], expected: list[bool | None])", "parametrize": "operations, inputs, expected", - "test_cases": "[([\"Trie\", \"insert\", \"insert\", \"search\", \"search\", \"search\"], [[], [\"app\"], [\"apple\"], [\"app\"], [\"apple\"], [\"appl\"]], [None, None, None, True, True, False]), ([\"Trie\", \"insert\", \"insert\", \"insert\", \"search\", \"search\", \"search\"], [[], [\"cat\"], [\"car\"], [\"card\"], [\"cat\"], [\"car\"], [\"care\"]], [None, None, None, None, True, True, False]), ([\"Trie\", \"insert\", \"insert\", \"starts_with\", \"starts_with\", \"starts_with\"], [[], [\"test\"], [\"testing\"], [\"test\"], [\"testing\"], [\"te\"]], [None, None, None, True, True, True]), ([\"Trie\", \"insert\", \"search\", \"search\", \"insert\", \"search\", \"search\"], [[], [\"abc\"], [\"abc\"], [\"ab\"], [\"ab\"], [\"ab\"], [\"abc\"]], [None, None, True, False, None, True, True]), ([\"Trie\", \"insert\", \"search\", \"starts_with\"], [[], [\"a\"], [\"a\"], [\"a\"]], [None, None, True, True]), ([\"Trie\", \"search\", \"starts_with\"], [[], [\"empty\"], [\"empty\"]], [None, False, False]), ([\"Trie\", \"insert\", \"insert\", \"search\", \"search\", \"starts_with\", \"starts_with\"], [[], [\"word\"], [\"world\"], [\"word\"], [\"world\"], [\"wor\"], [\"wo\"]], [None, None, None, True, True, True, True]), ([\"Trie\", \"insert\", \"insert\", \"insert\", \"search\", \"search\", \"search\", \"starts_with\"], [[], [\"aa\"], [\"aaa\"], [\"aaaa\"], [\"aa\"], [\"aaa\"], [\"aaaa\"], [\"a\"]], [None, None, None, None, True, True, True, True]), ([\"Trie\", \"insert\", \"search\", \"search\", \"starts_with\", \"starts_with\"], [[], [\"hello\"], [\"hello\"], [\"hell\"], [\"hello\"], [\"hel\"]], [None, None, True, False, True, True]), ([\"Trie\", \"insert\", \"insert\", \"insert\", \"search\", \"search\", \"search\", \"starts_with\", \"starts_with\"], [[], [\"she\"], [\"sells\"], [\"sea\"], [\"she\"], [\"shells\"], [\"sea\"], [\"se\"], [\"s\"]], [None, None, None, None, True, False, True, True, True]), ([\"Trie\", \"insert\", \"insert\", \"search\", \"search\", \"starts_with\", \"starts_with\", \"starts_with\"], [[], [\"programming\"], [\"program\"], [\"programming\"], [\"program\"], [\"prog\"], [\"programming\"], [\"programm\"]], [None, None, None, True, True, True, True, True]), ([\"Trie\", \"insert\", \"search\", \"starts_with\", \"insert\", \"search\", \"starts_with\"], [[], [\"z\"], [\"z\"], [\"z\"], [\"zzz\"], [\"zzz\"], [\"zz\"]], [None, None, True, True, None, True, True])]", + "test_cases": { + "list": [ + "([\"Trie\", \"insert\", \"insert\", \"search\", \"search\", \"search\"], [[], [\"app\"], [\"apple\"], [\"app\"], [\"apple\"], [\"appl\"]], [None, None, None, True, True, False])", + "([\"Trie\", \"insert\", \"insert\", \"insert\", \"search\", \"search\", \"search\"], [[], [\"cat\"], [\"car\"], [\"card\"], [\"cat\"], [\"car\"], [\"care\"]], [None, None, None, None, True, True, False])", + "([\"Trie\", \"insert\", \"insert\", \"starts_with\", \"starts_with\", \"starts_with\"], [[], [\"test\"], [\"testing\"], [\"test\"], [\"testing\"], [\"te\"]], [None, None, None, True, True, True])", + "([\"Trie\", \"insert\", \"search\", \"search\", \"insert\", \"search\", \"search\"], [[], [\"abc\"], [\"abc\"], [\"ab\"], [\"ab\"], [\"ab\"], [\"abc\"]], [None, None, True, False, None, True, True])", + "([\"Trie\", \"insert\", \"search\", \"starts_with\"], [[], [\"a\"], [\"a\"], [\"a\"]], [None, None, True, True])", + "([\"Trie\", \"search\", \"starts_with\"], [[], [\"empty\"], [\"empty\"]], [None, False, False])", + "([\"Trie\", \"insert\", \"insert\", \"search\", \"search\", \"starts_with\", \"starts_with\"], [[], [\"word\"], [\"world\"], [\"word\"], [\"world\"], [\"wor\"], [\"wo\"]], [None, None, None, True, True, True, True])", + "([\"Trie\", \"insert\", \"insert\", \"insert\", \"search\", \"search\", \"search\", \"starts_with\"], [[], [\"aa\"], [\"aaa\"], [\"aaaa\"], [\"aa\"], [\"aaa\"], [\"aaaa\"], [\"a\"]], [None, None, None, None, True, True, True, True])", + "([\"Trie\", \"insert\", \"search\", \"search\", \"starts_with\", \"starts_with\"], [[], [\"hello\"], [\"hello\"], [\"hell\"], [\"hello\"], [\"hel\"]], [None, None, True, False, True, True])", + "([\"Trie\", \"insert\", \"insert\", \"insert\", \"search\", \"search\", \"search\", \"starts_with\", \"starts_with\"], [[], [\"she\"], [\"sells\"], [\"sea\"], [\"she\"], [\"shells\"], [\"sea\"], [\"se\"], [\"s\"]], [None, None, None, None, True, False, True, True, True])", + "([\"Trie\", \"insert\", \"insert\", \"search\", \"search\", \"starts_with\", \"starts_with\", \"starts_with\"], [[], [\"programming\"], [\"program\"], [\"programming\"], [\"program\"], [\"prog\"], [\"programming\"], [\"programm\"]], [None, None, None, True, True, True, True, True])", + "([\"Trie\", \"insert\", \"search\", \"starts_with\", \"insert\", \"search\", \"starts_with\"], [[], [\"z\"], [\"z\"], [\"z\"], [\"zzz\"], [\"zzz\"], [\"zz\"]], [None, None, True, True, None, True, True])" + ] + }, "body": " result, _ = run_trie_operations(Trie, operations, inputs)\n assert_trie_operations(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/insert_interval.json b/leetcode_py/cli/resources/leetcode/json/problems/insert_interval.json index 5429660..749b2f6 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/insert_interval.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/insert_interval.json @@ -5,7 +5,9 @@ "problem_title": "Insert Interval", "difficulty": "Medium", "topics": "Array", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "You are given an array of non-overlapping intervals `intervals` where `intervals[i] = [starti, endi]` represent the start and the end of the ith interval and `intervals` is sorted in ascending order by `starti`. You are also given an interval `newInterval = [start, end]` that represents the start and end of another interval.\n\nInsert `newInterval` into `intervals` such that `intervals` is still sorted in ascending order by `starti` and `intervals` still does not have any overlapping intervals (merge overlapping intervals if necessary).\n\nReturn `intervals` after the insertion.", "_readme_examples": { "list": [ @@ -44,7 +46,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -52,7 +60,24 @@ "name": "test_insert", "signature": "(self, intervals: list[list[int]], new_interval: list[int], expected: list[list[int]])", "parametrize": "intervals, new_interval, expected", - "test_cases": "[([[1,3],[6,9]], [2,5], [[1,5],[6,9]]), ([[1,2],[3,5],[6,7],[8,10],[12,16]], [4,8], [[1,2],[3,10],[12,16]]), ([], [5,7], [[5,7]]), ([[1,5]], [2,3], [[1,5]]), ([[1,5]], [6,8], [[1,5],[6,8]]), ([[1,5]], [0,0], [[0,0],[1,5]]), ([[3,5],[12,15]], [6,6], [[3,5],[6,6],[12,15]]), ([[1,2],[4,5]], [3,3], [[1,2],[3,3],[4,5]]), ([[2,5],[6,7],[8,9]], [0,1], [[0,1],[2,5],[6,7],[8,9]]), ([[1,3],[6,9]], [10,12], [[1,3],[6,9],[10,12]]), ([[1,4],[5,6]], [2,3], [[1,4],[5,6]]), ([[1,2],[3,4],[5,6]], [0,7], [[0,7]]), ([[2,3],[5,6]], [1,4], [[1,4],[5,6]]), ([[1,5],[10,15]], [6,9], [[1,5],[6,9],[10,15]])]", + "test_cases": { + "list": [ + "([[1,3],[6,9]], [2,5], [[1,5],[6,9]])", + "([[1,2],[3,5],[6,7],[8,10],[12,16]], [4,8], [[1,2],[3,10],[12,16]])", + "([], [5,7], [[5,7]])", + "([[1,5]], [2,3], [[1,5]])", + "([[1,5]], [6,8], [[1,5],[6,8]])", + "([[1,5]], [0,0], [[0,0],[1,5]])", + "([[3,5],[12,15]], [6,6], [[3,5],[6,6],[12,15]])", + "([[1,2],[4,5]], [3,3], [[1,2],[3,3],[4,5]])", + "([[2,5],[6,7],[8,9]], [0,1], [[0,1],[2,5],[6,7],[8,9]])", + "([[1,3],[6,9]], [10,12], [[1,3],[6,9],[10,12]])", + "([[1,4],[5,6]], [2,3], [[1,4],[5,6]])", + "([[1,2],[3,4],[5,6]], [0,7], [[0,7]])", + "([[2,3],[5,6]], [1,4], [[1,4],[5,6]])", + "([[1,5],[10,15]], [6,9], [[1,5],[6,9],[10,15]])" + ] + }, "body": " result = run_insert(Solution, intervals, new_interval)\n assert_insert(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/invert_binary_tree.json b/leetcode_py/cli/resources/leetcode/json/problems/invert_binary_tree.json index 4d8af88..7ef373d 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/invert_binary_tree.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/invert_binary_tree.json @@ -5,13 +5,21 @@ "problem_title": "Invert Binary Tree", "difficulty": "Easy", "topics": "Tree, Depth-First Search, Breadth-First Search, Binary Tree", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "Given the `root` of a binary tree, invert the tree, and return its root.", "_readme_examples": { "list": [ - { "content": "```\nInput: root = [4,2,7,1,3,6,9]\nOutput: [4,7,2,9,6,3,1]\n```" }, - { "content": "```\nInput: root = [2,1,3]\nOutput: [2,3,1]\n```" }, - { "content": "```\nInput: root = []\nOutput: []\n```" } + { + "content": "```\nInput: root = [4,2,7,1,3,6,9]\nOutput: [4,7,2,9,6,3,1]\n```" + }, + { + "content": "```\nInput: root = [2,1,3]\nOutput: [2,3,1]\n```" + }, + { + "content": "```\nInput: root = []\nOutput: []\n```" + } ] }, "readme_constraints": "- The number of nodes in the tree is in the range [0, 100]\n- -100 <= Node.val <= 100", @@ -41,7 +49,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -49,7 +63,25 @@ "name": "test_invert_tree", "signature": "(self, root_list: list[int | None], expected_list: list[int | None])", "parametrize": "root_list, expected_list", - "test_cases": "[([4, 2, 7, 1, 3, 6, 9], [4, 7, 2, 9, 6, 3, 1]), ([2, 1, 3], [2, 3, 1]), ([], []), ([1], [1]), ([1, 2], [1, None, 2]), ([1, None, 2], [1, 2]), ([1, 2, 3, 4, 5], [1, 3, 2, None, None, 5, 4]), ([1, 2, 3, None, None, 4, 5], [1, 3, 2, 5, 4]), ([1, 2, 3, 4, 5, 6, 7], [1, 3, 2, 7, 6, 5, 4]), ([5, 3, 8, 2, 4, 7, 9], [5, 8, 3, 9, 7, 4, 2]), ([10, 5, 15, None, 6, 12, 20], [10, 15, 5, 20, 12, 6]), ([1, 2, None, 3], [1, None, 2, None, 3]), ([0, -1, 1], [0, 1, -1]), ([100, 50, 150], [100, 150, 50]), ([1, 2, 3, None, 4, None, 5], [1, 3, 2, 5, None, 4])]", + "test_cases": { + "list": [ + "([4, 2, 7, 1, 3, 6, 9], [4, 7, 2, 9, 6, 3, 1])", + "([2, 1, 3], [2, 3, 1])", + "([], [])", + "([1], [1])", + "([1, 2], [1, None, 2])", + "([1, None, 2], [1, 2])", + "([1, 2, 3, 4, 5], [1, 3, 2, None, None, 5, 4])", + "([1, 2, 3, None, None, 4, 5], [1, 3, 2, 5, 4])", + "([1, 2, 3, 4, 5, 6, 7], [1, 3, 2, 7, 6, 5, 4])", + "([5, 3, 8, 2, 4, 7, 9], [5, 8, 3, 9, 7, 4, 2])", + "([10, 5, 15, None, 6, 12, 20], [10, 15, 5, 20, 12, 6])", + "([1, 2, None, 3], [1, None, 2, None, 3])", + "([0, -1, 1], [0, 1, -1])", + "([100, 50, 150], [100, 150, 50])", + "([1, 2, 3, None, 4, None, 5], [1, 3, 2, 5, None, 4])" + ] + }, "body": " result = run_invert_tree(Solution, root_list)\n assert_invert_tree(result, expected_list)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/jump_game.json b/leetcode_py/cli/resources/leetcode/json/problems/jump_game.json index dc095cf..46ac915 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/jump_game.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/jump_game.json @@ -5,7 +5,9 @@ "problem_title": "Jump Game", "difficulty": "Medium", "topics": "Array, Dynamic Programming, Greedy", - "_tags": { "list": ["blind-75"] }, + "_tags": { + "list": ["blind-75"] + }, "readme_description": "You are given an integer array `nums`. You are initially positioned at the array's **first index**, and each element in the array represents your maximum jump length at that position.\n\nReturn `true` *if you can reach the last index, or* `false` *otherwise*.", "_readme_examples": { "list": [ @@ -44,7 +46,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -52,7 +60,25 @@ "name": "test_can_jump", "signature": "(self, nums: list[int], expected: bool)", "parametrize": "nums, expected", - "test_cases": "[([2, 3, 1, 1, 4], True), ([3, 2, 1, 0, 4], False), ([0], True), ([1], True), ([1, 0], True), ([0, 1], False), ([2, 0, 0], True), ([1, 1, 1, 0], True), ([3, 0, 8, 2, 0, 0, 1], True), ([1, 0, 1, 0], False), ([2, 5, 0, 0], True), ([1, 2, 3], True), ([5, 4, 3, 2, 1, 0, 0], False), ([1, 1, 2, 2, 0, 1, 1], True), ([4, 2, 0, 0, 1, 1, 4, 4, 4, 0, 4, 0], True)]", + "test_cases": { + "list": [ + "([2, 3, 1, 1, 4], True)", + "([3, 2, 1, 0, 4], False)", + "([0], True)", + "([1], True)", + "([1, 0], True)", + "([0, 1], False)", + "([2, 0, 0], True)", + "([1, 1, 1, 0], True)", + "([3, 0, 8, 2, 0, 0, 1], True)", + "([1, 0, 1, 0], False)", + "([2, 5, 0, 0], True)", + "([1, 2, 3], True)", + "([5, 4, 3, 2, 1, 0, 0], False)", + "([1, 1, 2, 2, 0, 1, 1], True)", + "([4, 2, 0, 0, 1, 1, 4, 4, 4, 0, 4, 0], True)" + ] + }, "body": " result = run_can_jump(Solution, nums)\n assert_can_jump(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/k_closest_points_to_origin.json b/leetcode_py/cli/resources/leetcode/json/problems/k_closest_points_to_origin.json index 4c0523b..7b02eb8 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/k_closest_points_to_origin.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/k_closest_points_to_origin.json @@ -5,8 +5,10 @@ "problem_title": "K Closest Points to Origin", "difficulty": "Medium", "topics": "Array, Math, Divide and Conquer, Geometry, Sorting, Heap (Priority Queue), Quickselect", - "_tags": { "list": ["grind-75"] }, - "readme_description": "Given an array of `points` where `points[i] = [xi, yi]` represents a point on the **X-Y** plane and an integer `k`, return the `k` closest points to the origin `(0, 0)`.\n\nThe distance between two points on the **X-Y** plane is the Euclidean distance (i.e., `\u221a(x1 - x2)\u00b2 + (y1 - y2)\u00b2`).\n\nYou may return the answer in **any order**. The answer is **guaranteed** to be **unique** (except for the order that it is in).", + "_tags": { + "list": ["grind-75"] + }, + "readme_description": "Given an array of `points` where `points[i] = [xi, yi]` represents a point on the **X-Y** plane and an integer `k`, return the `k` closest points to the origin `(0, 0)`.\n\nThe distance between two points on the **X-Y** plane is the Euclidean distance (i.e., `√(x1 - x2)² + (y1 - y2)²`).\n\nYou may return the answer in **any order**. The answer is **guaranteed** to be **unique** (except for the order that it is in).", "_readme_examples": { "list": [ { @@ -44,7 +46,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -52,7 +60,22 @@ "name": "test_k_closest", "signature": "(self, points: list[list[int]], k: int, expected: list[list[int]])", "parametrize": "points, k, expected", - "test_cases": "[([[1, 3], [-2, 2]], 1, [[-2, 2]]), ([[3, 3], [5, -1], [-2, 4]], 2, [[3, 3], [-2, 4]]), ([[0, 1], [1, 0]], 2, [[0, 1], [1, 0]]), ([[1, 1], [1, 1], [1, 1]], 2, [[1, 1], [1, 1]]), ([[0, 0]], 1, [[0, 0]]), ([[1, 0], [2, 0], [3, 0]], 2, [[1, 0], [2, 0]]), ([[0, 3], [4, 0]], 1, [[0, 3]]), ([[-5, 4], [4, 6], [2, -1]], 1, [[2, -1]]), ([[1, 1], [2, 2], [3, 3]], 1, [[1, 1]]), ([[10, 10], [1, 1], [5, 5]], 2, [[1, 1], [5, 5]]), ([[-1, -1], [1, 1], [-1, 1], [1, -1]], 3, [[-1, 1], [1, -1], [1, 1]]), ([[6, 10], [-3, 3], [-2, 5], [0, 2]], 3, [[-3, 3], [0, 2], [-2, 5]])]", + "test_cases": { + "list": [ + "([[1, 3], [-2, 2]], 1, [[-2, 2]])", + "([[3, 3], [5, -1], [-2, 4]], 2, [[3, 3], [-2, 4]])", + "([[0, 1], [1, 0]], 2, [[0, 1], [1, 0]])", + "([[1, 1], [1, 1], [1, 1]], 2, [[1, 1], [1, 1]])", + "([[0, 0]], 1, [[0, 0]])", + "([[1, 0], [2, 0], [3, 0]], 2, [[1, 0], [2, 0]])", + "([[0, 3], [4, 0]], 1, [[0, 3]])", + "([[-5, 4], [4, 6], [2, -1]], 1, [[2, -1]])", + "([[1, 1], [2, 2], [3, 3]], 1, [[1, 1]])", + "([[10, 10], [1, 1], [5, 5]], 2, [[1, 1], [5, 5]])", + "([[-1, -1], [1, 1], [-1, 1], [1, -1]], 3, [[-1, 1], [1, -1], [1, 1]])", + "([[6, 10], [-3, 3], [-2, 5], [0, 2]], 3, [[-3, 3], [0, 2], [-2, 5]])" + ] + }, "body": " result = run_k_closest(Solution, points, k)\n assert_k_closest(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/kth_smallest_element_in_a_bst.json b/leetcode_py/cli/resources/leetcode/json/problems/kth_smallest_element_in_a_bst.json index 0c10237..16aae61 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/kth_smallest_element_in_a_bst.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/kth_smallest_element_in_a_bst.json @@ -5,7 +5,9 @@ "problem_title": "Kth Smallest Element in a BST", "difficulty": "Medium", "topics": "Tree, Depth-First Search, Binary Search Tree, Binary Tree", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "Given the `root` of a binary search tree, and an integer `k`, return the `k`th smallest value (1-indexed) of all the values of the nodes in the tree.", "_readme_examples": { "list": [ @@ -44,7 +46,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -52,7 +60,22 @@ "name": "test_kth_smallest", "signature": "(self, root_list: list[int | None], k: int, expected: int)", "parametrize": "root_list, k, expected", - "test_cases": "[([3, 1, 4, None, 2], 1, 1), ([5, 3, 6, 2, 4, None, None, 1], 3, 3), ([1], 1, 1), ([2, 1, 3], 2, 2), ([4, 2, 6, 1, 3, 5, 7], 4, 4), ([1, None, 2], 2, 2), ([5, 3, 6, 2, 4, None, None, 1], 1, 1), ([5, 3, 6, 2, 4, None, None, 1], 4, 4), ([10, 5, 15, 3, 7, 12, 20], 1, 3), ([10, 5, 15, 3, 7, 12, 20], 7, 20), ([1, None, 2, None, 3], 3, 3), ([3, 1, 4, None, 2], 4, 4)]", + "test_cases": { + "list": [ + "([3, 1, 4, None, 2], 1, 1)", + "([5, 3, 6, 2, 4, None, None, 1], 3, 3)", + "([1], 1, 1)", + "([2, 1, 3], 2, 2)", + "([4, 2, 6, 1, 3, 5, 7], 4, 4)", + "([1, None, 2], 2, 2)", + "([5, 3, 6, 2, 4, None, None, 1], 1, 1)", + "([5, 3, 6, 2, 4, None, None, 1], 4, 4)", + "([10, 5, 15, 3, 7, 12, 20], 1, 3)", + "([10, 5, 15, 3, 7, 12, 20], 7, 20)", + "([1, None, 2, None, 3], 3, 3)", + "([3, 1, 4, None, 2], 4, 4)" + ] + }, "body": " result = run_kth_smallest(Solution, root_list, k)\n assert_kth_smallest(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/largest_rectangle_in_histogram.json b/leetcode_py/cli/resources/leetcode/json/problems/largest_rectangle_in_histogram.json index e76b075..3a91f31 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/largest_rectangle_in_histogram.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/largest_rectangle_in_histogram.json @@ -5,7 +5,9 @@ "problem_title": "Largest Rectangle in Histogram", "difficulty": "Hard", "topics": "Array, Stack, Monotonic Stack", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "Given an array of integers `heights` representing the histogram's bar height where the width of each bar is `1`, return the area of the largest rectangle in the histogram.", "_readme_examples": { "list": [ @@ -44,7 +46,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -52,7 +60,26 @@ "name": "test_largest_rectangle_area", "signature": "(self, heights: list[int], expected: int)", "parametrize": "heights, expected", - "test_cases": "[([2, 1, 5, 6, 2, 3], 10), ([2, 4], 4), ([1], 1), ([0], 0), ([1, 1], 2), ([0, 0, 0], 0), ([1, 2, 3, 4, 5], 9), ([5, 4, 3, 2, 1], 9), ([3, 3, 3, 3], 12), ([2, 1, 2], 3), ([1, 3, 1], 3), ([6, 7, 5, 2, 4, 5, 9, 3], 16), ([4, 2, 0, 3, 2, 5], 6), ([1, 2, 2, 1], 4), ([0, 9], 9), ([9, 0], 9)]", + "test_cases": { + "list": [ + "([2, 1, 5, 6, 2, 3], 10)", + "([2, 4], 4)", + "([1], 1)", + "([0], 0)", + "([1, 1], 2)", + "([0, 0, 0], 0)", + "([1, 2, 3, 4, 5], 9)", + "([5, 4, 3, 2, 1], 9)", + "([3, 3, 3, 3], 12)", + "([2, 1, 2], 3)", + "([1, 3, 1], 3)", + "([6, 7, 5, 2, 4, 5, 9, 3], 16)", + "([4, 2, 0, 3, 2, 5], 6)", + "([1, 2, 2, 1], 4)", + "([0, 9], 9)", + "([9, 0], 9)" + ] + }, "body": " result = run_largest_rectangle_area(Solution, heights)\n assert_largest_rectangle_area(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/letter_combinations_of_a_phone_number.json b/leetcode_py/cli/resources/leetcode/json/problems/letter_combinations_of_a_phone_number.json index 0fb1f5f..c4d40f7 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/letter_combinations_of_a_phone_number.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/letter_combinations_of_a_phone_number.json @@ -5,15 +5,21 @@ "problem_title": "Letter Combinations of a Phone Number", "difficulty": "Medium", "topics": "Hash Table, String, Backtracking", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "Given a string containing digits from `2-9` inclusive, return all possible letter combinations that the number could represent. Return the answer in **any order**.\n\nA mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters.", "_readme_examples": { "list": [ { "content": "![Phone Keypad](https://assets.leetcode.com/uploads/2022/03/15/1200px-telephone-keypad2svg.png)\n\n```\nInput: digits = \"23\"\nOutput: [\"ad\",\"ae\",\"af\",\"bd\",\"be\",\"bf\",\"cd\",\"ce\",\"cf\"]\n```" }, - { "content": "```\nInput: digits = \"\"\nOutput: []\n```" }, - { "content": "```\nInput: digits = \"2\"\nOutput: [\"a\",\"b\",\"c\"]\n```" } + { + "content": "```\nInput: digits = \"\"\nOutput: []\n```" + }, + { + "content": "```\nInput: digits = \"2\"\nOutput: [\"a\",\"b\",\"c\"]\n```" + } ] }, "readme_constraints": "- `0 <= digits.length <= 4`\n- `digits[i]` is a digit in the range `['2', '9']`.", @@ -43,7 +49,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -51,7 +63,22 @@ "name": "test_letter_combinations", "signature": "(self, digits: str, expected: list[str])", "parametrize": "digits, expected", - "test_cases": "[('23', ['ad', 'ae', 'af', 'bd', 'be', 'bf', 'cd', 'ce', 'cf']), ('', []), ('2', ['a', 'b', 'c']), ('234', ['adg', 'adh', 'adi', 'aeg', 'aeh', 'aei', 'afg', 'afh', 'afi', 'bdg', 'bdh', 'bdi', 'beg', 'beh', 'bei', 'bfg', 'bfh', 'bfi', 'cdg', 'cdh', 'cdi', 'ceg', 'ceh', 'cei', 'cfg', 'cfh', 'cfi']), ('7', ['p', 'q', 'r', 's']), ('9', ['w', 'x', 'y', 'z']), ('79', ['pw', 'px', 'py', 'pz', 'qw', 'qx', 'qy', 'qz', 'rw', 'rx', 'ry', 'rz', 'sw', 'sx', 'sy', 'sz']), ('22', ['aa', 'ab', 'ac', 'ba', 'bb', 'bc', 'ca', 'cb', 'cc']), ('3456', ['dgjm', 'dgjn', 'dgjo', 'dgkm', 'dgkn', 'dgko', 'dglm', 'dgln', 'dglo', 'dhjm', 'dhjn', 'dhjo', 'dhkm', 'dhkn', 'dhko', 'dhlm', 'dhln', 'dhlo', 'dijm', 'dijn', 'dijo', 'dikm', 'dikn', 'diko', 'dilm', 'diln', 'dilo', 'egjm', 'egjn', 'egjo', 'egkm', 'egkn', 'egko', 'eglm', 'egln', 'eglo', 'ehjm', 'ehjn', 'ehjo', 'ehkm', 'ehkn', 'ehko', 'ehlm', 'ehln', 'ehlo', 'eijm', 'eijn', 'eijo', 'eikm', 'eikn', 'eiko', 'eilm', 'eiln', 'eilo', 'fgjm', 'fgjn', 'fgjo', 'fgkm', 'fgkn', 'fgko', 'fglm', 'fgln', 'fglo', 'fhjm', 'fhjn', 'fhjo', 'fhkm', 'fhkn', 'fhko', 'fhlm', 'fhln', 'fhlo', 'fijm', 'fijn', 'fijo', 'fikm', 'fikn', 'fiko', 'film', 'filn', 'filo']), ('25', ['aj', 'ak', 'al', 'bj', 'bk', 'bl', 'cj', 'ck', 'cl']), ('78', ['pt', 'pu', 'pv', 'qt', 'qu', 'qv', 'rt', 'ru', 'rv', 'st', 'su', 'sv']), ('89', ['tw', 'tx', 'ty', 'tz', 'uw', 'ux', 'uy', 'uz', 'vw', 'vx', 'vy', 'vz'])]", + "test_cases": { + "list": [ + "('23', ['ad', 'ae', 'af', 'bd', 'be', 'bf', 'cd', 'ce', 'cf'])", + "('', [])", + "('2', ['a', 'b', 'c'])", + "('234', ['adg', 'adh', 'adi', 'aeg', 'aeh', 'aei', 'afg', 'afh', 'afi', 'bdg', 'bdh', 'bdi', 'beg', 'beh', 'bei', 'bfg', 'bfh', 'bfi', 'cdg', 'cdh', 'cdi', 'ceg', 'ceh', 'cei', 'cfg', 'cfh', 'cfi'])", + "('7', ['p', 'q', 'r', 's'])", + "('9', ['w', 'x', 'y', 'z'])", + "('79', ['pw', 'px', 'py', 'pz', 'qw', 'qx', 'qy', 'qz', 'rw', 'rx', 'ry', 'rz', 'sw', 'sx', 'sy', 'sz'])", + "('22', ['aa', 'ab', 'ac', 'ba', 'bb', 'bc', 'ca', 'cb', 'cc'])", + "('3456', ['dgjm', 'dgjn', 'dgjo', 'dgkm', 'dgkn', 'dgko', 'dglm', 'dgln', 'dglo', 'dhjm', 'dhjn', 'dhjo', 'dhkm', 'dhkn', 'dhko', 'dhlm', 'dhln', 'dhlo', 'dijm', 'dijn', 'dijo', 'dikm', 'dikn', 'diko', 'dilm', 'diln', 'dilo', 'egjm', 'egjn', 'egjo', 'egkm', 'egkn', 'egko', 'eglm', 'egln', 'eglo', 'ehjm', 'ehjn', 'ehjo', 'ehkm', 'ehkn', 'ehko', 'ehlm', 'ehln', 'ehlo', 'eijm', 'eijn', 'eijo', 'eikm', 'eikn', 'eiko', 'eilm', 'eiln', 'eilo', 'fgjm', 'fgjn', 'fgjo', 'fgkm', 'fgkn', 'fgko', 'fglm', 'fgln', 'fglo', 'fhjm', 'fhjn', 'fhjo', 'fhkm', 'fhkn', 'fhko', 'fhlm', 'fhln', 'fhlo', 'fijm', 'fijn', 'fijo', 'fikm', 'fikn', 'fiko', 'film', 'filn', 'filo'])", + "('25', ['aj', 'ak', 'al', 'bj', 'bk', 'bl', 'cj', 'ck', 'cl'])", + "('78', ['pt', 'pu', 'pv', 'qt', 'qu', 'qv', 'rt', 'ru', 'rv', 'st', 'su', 'sv'])", + "('89', ['tw', 'tx', 'ty', 'tz', 'uw', 'ux', 'uy', 'uz', 'vw', 'vx', 'vy', 'vz'])" + ] + }, "body": " result = run_letter_combinations(Solution, digits)\n assert_letter_combinations(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/linked_list_cycle.json b/leetcode_py/cli/resources/leetcode/json/problems/linked_list_cycle.json index be053cb..6a76f65 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/linked_list_cycle.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/linked_list_cycle.json @@ -5,7 +5,9 @@ "problem_title": "Linked List Cycle", "difficulty": "Easy", "topics": "Hash Table, Linked List, Two Pointers", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "Given `head`, the head of a linked list, determine if the linked list has a cycle in it.\n\nThere is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the `next` pointer. Internally, `pos` is used to denote the index of the node that tail's `next` pointer is connected to. **Note that `pos` is not passed as a parameter**.\n\nReturn `true` *if there is a cycle in the linked list*. Otherwise, return `false`.", "_readme_examples": { "list": [ @@ -47,7 +49,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -55,7 +63,25 @@ "name": "test_has_cycle", "signature": "(self, values: list[int], pos: int, expected: bool)", "parametrize": "values, pos, expected", - "test_cases": "[([3, 2, 0, -4], 1, True), ([1, 2], 0, True), ([1], -1, False), ([], -1, False), ([1, 2, 3], -1, False), ([1, 2, 3, 4, 5], 0, True), ([1, 2, 3, 4, 5], 2, True), ([1, 2, 3, 4, 5], 4, True), ([1], 0, True), ([1, 2], 1, True), ([1, 2, 3, 4], -1, False), ([1, 2, 3, 4, 5, 6], 3, True), ([10, 20, 30], 1, True), ([100], -1, False), ([1, 2, 3, 4, 5, 6, 7, 8], 5, True)]", + "test_cases": { + "list": [ + "([3, 2, 0, -4], 1, True)", + "([1, 2], 0, True)", + "([1], -1, False)", + "([], -1, False)", + "([1, 2, 3], -1, False)", + "([1, 2, 3, 4, 5], 0, True)", + "([1, 2, 3, 4, 5], 2, True)", + "([1, 2, 3, 4, 5], 4, True)", + "([1], 0, True)", + "([1, 2], 1, True)", + "([1, 2, 3, 4], -1, False)", + "([1, 2, 3, 4, 5, 6], 3, True)", + "([10, 20, 30], 1, True)", + "([100], -1, False)", + "([1, 2, 3, 4, 5, 6, 7, 8], 5, True)" + ] + }, "body": " result = run_has_cycle(Solution, values, pos)\n assert_has_cycle(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/longest_consecutive_sequence.json b/leetcode_py/cli/resources/leetcode/json/problems/longest_consecutive_sequence.json index 4450914..e4ce691 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/longest_consecutive_sequence.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/longest_consecutive_sequence.json @@ -5,15 +5,21 @@ "problem_title": "Longest Consecutive Sequence", "difficulty": "Medium", "topics": "Array, Hash Table, Union Find", - "_tags": { "list": ["grind"] }, + "_tags": { + "list": ["grind"] + }, "readme_description": "Given an unsorted array of integers `nums`, return *the length of the longest consecutive elements sequence.*\n\nYou must write an algorithm that runs in `O(n)` time.", "_readme_examples": { "list": [ { "content": "```\nInput: nums = [100,4,200,1,3,2]\nOutput: 4\nExplanation: The longest consecutive elements sequence is [1, 2, 3, 4]. Therefore its length is 4.\n```" }, - { "content": "```\nInput: nums = [0,3,7,2,5,8,4,6,0,1]\nOutput: 9\n```" }, - { "content": "```\nInput: nums = [1,0,1,2]\nOutput: 3\n```" } + { + "content": "```\nInput: nums = [0,3,7,2,5,8,4,6,0,1]\nOutput: 9\n```" + }, + { + "content": "```\nInput: nums = [1,0,1,2]\nOutput: 3\n```" + } ] }, "readme_constraints": "- 0 <= nums.length <= 10^5\n- -10^9 <= nums[i] <= 10^9", @@ -43,7 +49,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -51,7 +63,25 @@ "name": "test_longest_consecutive", "signature": "(self, nums: list[int], expected: int)", "parametrize": "nums, expected", - "test_cases": "[([100, 4, 200, 1, 3, 2], 4), ([0, 3, 7, 2, 5, 8, 4, 6, 0, 1], 9), ([1, 0, 1, 2], 3), ([], 0), ([1], 1), ([1, 2, 3, 4, 5], 5), ([5, 4, 3, 2, 1], 5), ([1, 3, 5, 7, 9], 1), ([1, 2, 0, 1], 3), ([9, 1, 4, 7, 3, -1, 0, 5, 8, -1, 6], 7), ([-1, -2, -3, -4, -5], 5), ([1000000000, -1000000000], 1), ([1, 2, 3, 5, 6, 7, 8], 4), ([10, 5, 12, 3, 55, 30, 4, 11, 2], 4), ([1, 9, 3, 10, 4, 20, 2], 4)]", + "test_cases": { + "list": [ + "([100, 4, 200, 1, 3, 2], 4)", + "([0, 3, 7, 2, 5, 8, 4, 6, 0, 1], 9)", + "([1, 0, 1, 2], 3)", + "([], 0)", + "([1], 1)", + "([1, 2, 3, 4, 5], 5)", + "([5, 4, 3, 2, 1], 5)", + "([1, 3, 5, 7, 9], 1)", + "([1, 2, 0, 1], 3)", + "([9, 1, 4, 7, 3, -1, 0, 5, 8, -1, 6], 7)", + "([-1, -2, -3, -4, -5], 5)", + "([1000000000, -1000000000], 1)", + "([1, 2, 3, 5, 6, 7, 8], 4)", + "([10, 5, 12, 3, 55, 30, 4, 11, 2], 4)", + "([1, 9, 3, 10, 4, 20, 2], 4)" + ] + }, "body": " result = run_longest_consecutive(Solution, nums)\n assert_longest_consecutive(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/longest_increasing_subsequence.json b/leetcode_py/cli/resources/leetcode/json/problems/longest_increasing_subsequence.json index c2032bf..e066696 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/longest_increasing_subsequence.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/longest_increasing_subsequence.json @@ -5,21 +5,25 @@ "problem_title": "Longest Increasing Subsequence", "difficulty": "Medium", "topics": "Array, Binary Search, Dynamic Programming", - "_tags": { "list": ["grind"] }, - + "_tags": { + "list": ["grind"] + }, "readme_description": "Given an integer array `nums`, return the length of the longest **strictly increasing** **subsequence**.", "_readme_examples": { "list": [ { "content": "```\nInput: nums = [10,9,2,5,3,7,101,18]\nOutput: 4\nExplanation: The longest increasing subsequence is [2,3,7,101], therefore the length is 4.\n```" }, - { "content": "```\nInput: nums = [0,1,0,3,2,3]\nOutput: 4\n```" }, - { "content": "```\nInput: nums = [7,7,7,7,7,7,7]\nOutput: 1\n```" } + { + "content": "```\nInput: nums = [0,1,0,3,2,3]\nOutput: 4\n```" + }, + { + "content": "```\nInput: nums = [7,7,7,7,7,7,7]\nOutput: 1\n```" + } ] }, "readme_constraints": "- `1 <= nums.length <= 2500`\n- `-10^4 <= nums[i] <= 10^4`", "readme_additional": "**Follow up:** Can you come up with an algorithm that runs in `O(n log(n))` time complexity?", - "helpers_imports": "", "helpers_content": "", "helpers_run_name": "length_of_lis", @@ -28,16 +32,13 @@ "helpers_assert_name": "length_of_lis", "helpers_assert_signature": "(result: int, expected: int) -> bool", "helpers_assert_body": " assert result == expected\n return True", - "solution_imports": "", "solution_contents": "", "solution_class_content": "", - "test_imports": "import pytest\nfrom leetcode_py import logged_test\nfrom .helpers import assert_length_of_lis, run_length_of_lis\nfrom .solution import Solution", "test_content": "", "test_class_name": "LongestIncreasingSubsequence", "test_class_content": " def setup_method(self):\n self.solution = Solution()", - "_solution_methods": { "list": [ { @@ -47,23 +48,44 @@ } ] }, - "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, - "_test_methods": { "list": [ { "name": "test_length_of_lis", "signature": "(self, nums: list[int], expected: int)", "parametrize": "nums, expected", - "test_cases": "[([10, 9, 2, 5, 3, 7, 101, 18], 4), ([0, 1, 0, 3, 2, 3], 4), ([7, 7, 7, 7, 7, 7, 7], 1), ([1, 3, 6, 7, 9, 4, 10, 5, 6], 6), ([10, 22, 9, 33, 21, 50, 41, 60], 5), ([1], 1), ([1, 2], 2), ([2, 1], 1), ([1, 2, 3, 4, 5], 5), ([5, 4, 3, 2, 1], 1), ([4, 10, 4, 3, 8, 9], 3), ([2, 2], 1), ([1, 3, 2, 4], 3), ([10, 9, 2, 5, 3, 4], 3), ([1, 2, 3, 2, 3, 4, 5], 5)]", + "test_cases": { + "list": [ + "([10, 9, 2, 5, 3, 7, 101, 18], 4)", + "([0, 1, 0, 3, 2, 3], 4)", + "([7, 7, 7, 7, 7, 7, 7], 1)", + "([1, 3, 6, 7, 9, 4, 10, 5, 6], 6)", + "([10, 22, 9, 33, 21, 50, 41, 60], 5)", + "([1], 1)", + "([1, 2], 2)", + "([2, 1], 1)", + "([1, 2, 3, 4, 5], 5)", + "([5, 4, 3, 2, 1], 1)", + "([4, 10, 4, 3, 8, 9], 3)", + "([2, 2], 1)", + "([1, 3, 2, 4], 3)", + "([10, 9, 2, 5, 3, 4], 3)", + "([1, 2, 3, 2, 3, 4, 5], 5)" + ] + }, "body": " result = run_length_of_lis(Solution, nums)\n assert_length_of_lis(result, expected)" } ] }, - "playground_imports": "from helpers import run_length_of_lis, assert_length_of_lis\nfrom solution import Solution", "playground_setup": "# Example test case\nnums = [10, 9, 2, 5, 3, 7, 101, 18]\nexpected = 4", "playground_run": "result = run_length_of_lis(Solution, nums)\nresult", diff --git a/leetcode_py/cli/resources/leetcode/json/problems/longest_palindrome.json b/leetcode_py/cli/resources/leetcode/json/problems/longest_palindrome.json index 0307637..eea3e66 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/longest_palindrome.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/longest_palindrome.json @@ -5,7 +5,9 @@ "problem_title": "Longest Palindrome", "difficulty": "Easy", "topics": "Hash Table, String, Greedy", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "Given a string `s` which consists of lowercase or uppercase letters, return the length of the longest palindrome that can be built with those letters.\n\nLetters are case sensitive, for example, \"Aa\" is not considered a palindrome.", "_readme_examples": { "list": [ @@ -44,7 +46,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -52,7 +60,23 @@ "name": "test_longest_palindrome", "signature": "(self, s: str, expected: int)", "parametrize": "s, expected", - "test_cases": "[('abccccdd', 7), ('a', 1), ('Aa', 1), ('aabbcc', 6), ('', 0), ('aA', 1), ('abcdef', 1), ('aabbccdd', 8), ('aaaa', 4), ('abcdefg', 1), ('AAaa', 4), ('racecar', 7), ('abcABC', 1)]", + "test_cases": { + "list": [ + "('abccccdd', 7)", + "('a', 1)", + "('Aa', 1)", + "('aabbcc', 6)", + "('', 0)", + "('aA', 1)", + "('abcdef', 1)", + "('aabbccdd', 8)", + "('aaaa', 4)", + "('abcdefg', 1)", + "('AAaa', 4)", + "('racecar', 7)", + "('abcABC', 1)" + ] + }, "body": " result = run_longest_palindrome(Solution, s)\n assert_longest_palindrome(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/longest_palindromic_substring.json b/leetcode_py/cli/resources/leetcode/json/problems/longest_palindromic_substring.json index 81a4263..f19bee4 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/longest_palindromic_substring.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/longest_palindromic_substring.json @@ -5,14 +5,18 @@ "problem_title": "Longest Palindromic Substring", "difficulty": "Medium", "topics": "Two Pointers, String, Dynamic Programming", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "Given a string `s`, return the longest palindromic substring in `s`.", "_readme_examples": { "list": [ { "content": "```\nInput: s = \"babad\"\nOutput: \"bab\"\n```\n**Explanation:** \"aba\" is also a valid answer." }, - { "content": "```\nInput: s = \"cbbd\"\nOutput: \"bb\"\n```" } + { + "content": "```\nInput: s = \"cbbd\"\nOutput: \"bb\"\n```" + } ] }, "readme_constraints": "- `1 <= s.length <= 1000`\n- `s` consist of only digits and English letters.", @@ -42,7 +46,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -50,7 +60,22 @@ "name": "test_longest_palindrome", "signature": "(self, s: str, expected: set[str])", "parametrize": "s, expected", - "test_cases": "[('babad', {'bab', 'aba'}), ('cbbd', {'bb'}), ('a', {'a'}), ('ac', {'a', 'c'}), ('racecar', {'racecar'}), ('aabbaa', {'aabbaa'}), ('abacabad', {'abacaba'}), ('noon', {'noon'}), ('abccba', {'abccba'}), ('aa', {'aa'}), ('aba', {'aba'}), ('abcba', {'abcba'})]", + "test_cases": { + "list": [ + "('babad', {'bab', 'aba'})", + "('cbbd', {'bb'})", + "('a', {'a'})", + "('ac', {'a', 'c'})", + "('racecar', {'racecar'})", + "('aabbaa', {'aabbaa'})", + "('abacabad', {'abacaba'})", + "('noon', {'noon'})", + "('abccba', {'abccba'})", + "('aa', {'aa'})", + "('aba', {'aba'})", + "('abcba', {'abcba'})" + ] + }, "body": " result = run_longest_palindrome(Solution, s)\n assert_longest_palindrome(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/longest_substring_without_repeating_characters.json b/leetcode_py/cli/resources/leetcode/json/problems/longest_substring_without_repeating_characters.json index 5c4c6b0..e0c22d1 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/longest_substring_without_repeating_characters.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/longest_substring_without_repeating_characters.json @@ -5,7 +5,9 @@ "problem_title": "Longest Substring Without Repeating Characters", "difficulty": "Medium", "topics": "Hash Table, String, Sliding Window", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "Given a string `s`, find the length of the **longest** **substring** without duplicate characters.", "_readme_examples": { "list": [ @@ -47,7 +49,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -55,7 +63,23 @@ "name": "test_length_of_longest_substring", "signature": "(self, s: str, expected: int)", "parametrize": "s, expected", - "test_cases": "[('abcabcbb', 3), ('bbbbb', 1), ('pwwkew', 3), ('', 0), ('a', 1), ('au', 2), ('dvdf', 3), ('abcdef', 6), ('aab', 2), ('tmmzuxt', 5), (' ', 1), (' ', 1), ('abba', 2)]", + "test_cases": { + "list": [ + "('abcabcbb', 3)", + "('bbbbb', 1)", + "('pwwkew', 3)", + "('', 0)", + "('a', 1)", + "('au', 2)", + "('dvdf', 3)", + "('abcdef', 6)", + "('aab', 2)", + "('tmmzuxt', 5)", + "(' ', 1)", + "(' ', 1)", + "('abba', 2)" + ] + }, "body": " result = run_length_of_longest_substring(Solution, s)\n assert_length_of_longest_substring(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/lowest_common_ancestor_of_a_binary_search_tree.json b/leetcode_py/cli/resources/leetcode/json/problems/lowest_common_ancestor_of_a_binary_search_tree.json index 3eb7da0..2694877 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/lowest_common_ancestor_of_a_binary_search_tree.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/lowest_common_ancestor_of_a_binary_search_tree.json @@ -5,7 +5,9 @@ "problem_title": "Lowest Common Ancestor of a Binary Search Tree", "difficulty": "Medium", "topics": "Tree, Depth-First Search, Binary Search Tree, Binary Tree", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "Given a binary search tree (BST), find the lowest common ancestor (LCA) node of two given nodes in the BST.\n\nAccording to the definition of LCA on Wikipedia: \"The lowest common ancestor is defined between two nodes `p` and `q` as the lowest node in `T` that has both `p` and `q` as descendants (where we allow **a node to be a descendant of itself**).\"", "_readme_examples": { "list": [ @@ -15,7 +17,9 @@ { "content": "![Example 2](https://assets.leetcode.com/uploads/2018/12/14/binarysearchtree_improved.png)\n\n```\nInput: root = [6,2,8,0,4,7,9,null,null,3,5], p = 2, q = 4\nOutput: 2\n```\n**Explanation:** The LCA of nodes 2 and 4 is 2, since a node can be a descendant of itself according to the LCA definition." }, - { "content": "```\nInput: root = [2,1], p = 2, q = 1\nOutput: 2\n```" } + { + "content": "```\nInput: root = [2,1], p = 2, q = 1\nOutput: 2\n```" + } ] }, "readme_constraints": "- The number of nodes in the tree is in the range `[2, 10^5]`.\n- `-10^9 <= Node.val <= 10^9`\n- All `Node.val` are **unique**.\n- `p != q`\n- `p` and `q` will exist in the BST.", @@ -45,7 +49,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -53,7 +63,22 @@ "name": "test_lowest_common_ancestor", "signature": "(self, root_list: list[int | None], p_val: int, q_val: int, expected_val: int)", "parametrize": "root_list, p_val, q_val, expected_val", - "test_cases": "[([6, 2, 8, 0, 4, 7, 9, None, None, 3, 5], 2, 8, 6), ([6, 2, 8, 0, 4, 7, 9, None, None, 3, 5], 2, 4, 2), ([2, 1], 2, 1, 2), ([2, 1], 1, 2, 2), ([6, 2, 8, 0, 4, 7, 9], 0, 4, 2), ([6, 2, 8, 0, 4, 7, 9], 7, 9, 8), ([5, 3, 6, 2, 4, None, None, 1], 1, 4, 3), ([10, 5, 15, 3, 7, 12, 20], 3, 7, 5), ([1, None, 2], 1, 2, 1), ([3, 1, 4, None, 2], 1, 2, 1), ([20, 8, 22, 4, 12, None, None, None, None, 10, 14], 10, 14, 12), ([50, 30, 70, 20, 40, 60, 80], 20, 40, 30)]", + "test_cases": { + "list": [ + "([6, 2, 8, 0, 4, 7, 9, None, None, 3, 5], 2, 8, 6)", + "([6, 2, 8, 0, 4, 7, 9, None, None, 3, 5], 2, 4, 2)", + "([2, 1], 2, 1, 2)", + "([2, 1], 1, 2, 2)", + "([6, 2, 8, 0, 4, 7, 9], 0, 4, 2)", + "([6, 2, 8, 0, 4, 7, 9], 7, 9, 8)", + "([5, 3, 6, 2, 4, None, None, 1], 1, 4, 3)", + "([10, 5, 15, 3, 7, 12, 20], 3, 7, 5)", + "([1, None, 2], 1, 2, 1)", + "([3, 1, 4, None, 2], 1, 2, 1)", + "([20, 8, 22, 4, 12, None, None, None, None, 10, 14], 10, 14, 12)", + "([50, 30, 70, 20, 40, 60, 80], 20, 40, 30)" + ] + }, "body": " result = run_lowest_common_ancestor(Solution, root_list, p_val, q_val)\n assert_lowest_common_ancestor(result, expected_val)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/lowest_common_ancestor_of_a_binary_tree.json b/leetcode_py/cli/resources/leetcode/json/problems/lowest_common_ancestor_of_a_binary_tree.json index f5f5e36..8768e05 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/lowest_common_ancestor_of_a_binary_tree.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/lowest_common_ancestor_of_a_binary_tree.json @@ -5,7 +5,9 @@ "problem_title": "Lowest Common Ancestor of a Binary Tree", "difficulty": "Medium", "topics": "Tree, Depth-First Search, Binary Tree", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.\n\nAccording to the definition of LCA on Wikipedia: \"The lowest common ancestor is defined between two nodes `p` and `q` as the lowest node in `T` that has both `p` and `q` as descendants (where we allow **a node to be a descendant of itself**).\"", "_readme_examples": { "list": [ @@ -15,7 +17,9 @@ { "content": "\"\"\n\n```\nInput: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 4\nOutput: 5\nExplanation: The LCA of nodes 5 and 4 is 5, since a node can be a descendant of itself according to the LCA definition.\n```" }, - { "content": "```\nInput: root = [1,2], p = 1, q = 2\nOutput: 1\n```" } + { + "content": "```\nInput: root = [1,2], p = 1, q = 2\nOutput: 1\n```" + } ] }, "readme_constraints": "- The number of nodes in the tree is in the range [2, 10^5].\n- -10^9 <= Node.val <= 10^9\n- All Node.val are unique.\n- p != q\n- p and q will exist in the tree.", @@ -45,7 +49,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -53,7 +63,22 @@ "name": "test_lowest_common_ancestor", "signature": "(self, root_list: list[int | None], p_val: int, q_val: int, expected_val: int)", "parametrize": "root_list, p_val, q_val, expected_val", - "test_cases": "[([3,5,1,6,2,0,8,None,None,7,4], 5, 1, 3), ([3,5,1,6,2,0,8,None,None,7,4], 5, 4, 5), ([1,2], 1, 2, 1), ([2,1], 2, 1, 2), ([3,5,1,6,2,0,8,None,None,7,4], 6, 7, 5), ([3,5,1,6,2,0,8,None,None,7,4], 0, 8, 1), ([1, None, 2, None, 3], 2, 3, 2), ([4, 2, 6, 1, 3, 5, 7], 1, 7, 4), ([10, 5, 15, 3, 7, None, 18], 3, 7, 5), ([1, 2, 3, 4, 5, 6, 7], 4, 5, 2), ([20, 8, 22, 4, 12, None, 25], 4, 12, 8), ([50, 30, 70, 20, 40, 60, 80], 20, 40, 30)]", + "test_cases": { + "list": [ + "([3,5,1,6,2,0,8,None,None,7,4], 5, 1, 3)", + "([3,5,1,6,2,0,8,None,None,7,4], 5, 4, 5)", + "([1,2], 1, 2, 1)", + "([2,1], 2, 1, 2)", + "([3,5,1,6,2,0,8,None,None,7,4], 6, 7, 5)", + "([3,5,1,6,2,0,8,None,None,7,4], 0, 8, 1)", + "([1, None, 2, None, 3], 2, 3, 2)", + "([4, 2, 6, 1, 3, 5, 7], 1, 7, 4)", + "([10, 5, 15, 3, 7, None, 18], 3, 7, 5)", + "([1, 2, 3, 4, 5, 6, 7], 4, 5, 2)", + "([20, 8, 22, 4, 12, None, 25], 4, 12, 8)", + "([50, 30, 70, 20, 40, 60, 80], 20, 40, 30)" + ] + }, "body": " result = run_lowest_common_ancestor(Solution, root_list, p_val, q_val)\n assert_lowest_common_ancestor(result, expected_val)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/lru_cache.json b/leetcode_py/cli/resources/leetcode/json/problems/lru_cache.json index 2ecd230..50dbd85 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/lru_cache.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/lru_cache.json @@ -5,7 +5,9 @@ "problem_title": "LRU Cache", "difficulty": "Medium", "topics": "Hash Table, Linked List, Design, Doubly-Linked List", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "Design a data structure that follows the constraints of a Least Recently Used (LRU) cache.\n\nImplement the `LRUCache` class:\n\n- `LRUCache(int capacity)` Initialize the LRU cache with positive size capacity\n- `int get(int key)` Return the value of the key if the key exists, otherwise return -1\n- `void put(int key, int value)` Update the value of the key if the key exists. Otherwise, add the key-value pair to the cache. If the number of keys exceeds the capacity from this operation, evict the least recently used key\n\nThe functions `get` and `put` must each run in `O(1)` average time complexity.", "_readme_examples": { "list": [ @@ -50,14 +52,31 @@ } ] }, - "_test_helper_methods": { "list": [] }, + "_test_helper_methods": { + "list": [] + }, "_test_methods": { "list": [ { "name": "test_lru_cache", "signature": "(self, operations: list[str], inputs: list[list[int]], expected: list[int | None])", "parametrize": "operations, inputs, expected", - "test_cases": "[(['LRUCache', 'put', 'put', 'get', 'put', 'get', 'put', 'get', 'get', 'get'], [[2], [1, 1], [2, 2], [1], [3, 3], [2], [4, 4], [1], [3], [4]], [None, None, None, 1, None, -1, None, -1, 3, 4]), (['LRUCache', 'get', 'put', 'get', 'put', 'put', 'get', 'get'], [[2], [2], [2, 6], [1], [1, 5], [1, 2], [1], [2]], [None, -1, None, -1, None, None, 2, 6]), (['LRUCache', 'put', 'get', 'put', 'get', 'get'], [[1], [2, 1], [2], [3, 2], [2], [3]], [None, None, 1, None, -1, 2]), (['LRUCache', 'get'], [[1], [1]], [None, -1]), (['LRUCache', 'put', 'get'], [[1], [1, 100], [1]], [None, None, 100]), (['LRUCache', 'put', 'put', 'get', 'get'], [[2], [1, 1], [2, 2], [1], [2]], [None, None, None, 1, 2]), (['LRUCache', 'put', 'put', 'put', 'get', 'get', 'get'], [[2], [1, 1], [2, 2], [3, 3], [1], [2], [3]], [None, None, None, None, -1, 2, 3]), (['LRUCache', 'put', 'get', 'put', 'get', 'put', 'get'], [[3], [1, 1], [1], [2, 2], [2], [3, 3], [3]], [None, None, 1, None, 2, None, 3]), (['LRUCache', 'put', 'put', 'put', 'put', 'get', 'get'], [[3], [1, 1], [2, 2], [3, 3], [4, 4], [4], [3]], [None, None, None, None, None, 4, 3]), (['LRUCache', 'put', 'put', 'get', 'put', 'get', 'get'], [[2], [2, 1], [1, 1], [2], [4, 1], [1], [2]], [None, None, None, 1, None, -1, 1]), (['LRUCache', 'put', 'put', 'get', 'put', 'put', 'get'], [[2], [2, 1], [2, 2], [2], [1, 1], [4, 1], [2]], [None, None, None, 2, None, None, -1]), (['LRUCache', 'put', 'put', 'put', 'get', 'put', 'get', 'get', 'get', 'get'], [[3], [1, 1], [2, 2], [3, 3], [2], [4, 4], [1], [3], [4], [2]], [None, None, None, None, 2, None, -1, 3, 4, 2])]", + "test_cases": { + "list": [ + "(['LRUCache', 'put', 'put', 'get', 'put', 'get', 'put', 'get', 'get', 'get'], [[2], [1, 1], [2, 2], [1], [3, 3], [2], [4, 4], [1], [3], [4]], [None, None, None, 1, None, -1, None, -1, 3, 4])", + "(['LRUCache', 'get', 'put', 'get', 'put', 'put', 'get', 'get'], [[2], [2], [2, 6], [1], [1, 5], [1, 2], [1], [2]], [None, -1, None, -1, None, None, 2, 6])", + "(['LRUCache', 'put', 'get', 'put', 'get', 'get'], [[1], [2, 1], [2], [3, 2], [2], [3]], [None, None, 1, None, -1, 2])", + "(['LRUCache', 'get'], [[1], [1]], [None, -1])", + "(['LRUCache', 'put', 'get'], [[1], [1, 100], [1]], [None, None, 100])", + "(['LRUCache', 'put', 'put', 'get', 'get'], [[2], [1, 1], [2, 2], [1], [2]], [None, None, None, 1, 2])", + "(['LRUCache', 'put', 'put', 'put', 'get', 'get', 'get'], [[2], [1, 1], [2, 2], [3, 3], [1], [2], [3]], [None, None, None, None, -1, 2, 3])", + "(['LRUCache', 'put', 'get', 'put', 'get', 'put', 'get'], [[3], [1, 1], [1], [2, 2], [2], [3, 3], [3]], [None, None, 1, None, 2, None, 3])", + "(['LRUCache', 'put', 'put', 'put', 'put', 'get', 'get'], [[3], [1, 1], [2, 2], [3, 3], [4, 4], [4], [3]], [None, None, None, None, None, 4, 3])", + "(['LRUCache', 'put', 'put', 'get', 'put', 'get', 'get'], [[2], [2, 1], [1, 1], [2], [4, 1], [1], [2]], [None, None, None, 1, None, -1, 1])", + "(['LRUCache', 'put', 'put', 'get', 'put', 'put', 'get'], [[2], [2, 1], [2, 2], [2], [1, 1], [4, 1], [2]], [None, None, None, 2, None, None, -1])", + "(['LRUCache', 'put', 'put', 'put', 'get', 'put', 'get', 'get', 'get', 'get'], [[3], [1, 1], [2, 2], [3, 3], [2], [4, 4], [1], [3], [4], [2]], [None, None, None, None, 2, None, -1, 3, 4, 2])" + ] + }, "body": " result, _ = run_lru_cache(LRUCache, operations, inputs)\n assert_lru_cache(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/majority_element.json b/leetcode_py/cli/resources/leetcode/json/problems/majority_element.json index 01c8606..6369175 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/majority_element.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/majority_element.json @@ -5,12 +5,18 @@ "problem_title": "Majority Element", "difficulty": "Easy", "topics": "Array, Hash Table, Divide and Conquer, Sorting, Counting", - "_tags": { "list": ["grind-75"] }, - "readme_description": "Given an array `nums` of size `n`, return the majority element.\n\nThe majority element is the element that appears more than `\u230an / 2\u230b` times. You may assume that the majority element always exists in the array.", + "_tags": { + "list": ["grind-75"] + }, + "readme_description": "Given an array `nums` of size `n`, return the majority element.\n\nThe majority element is the element that appears more than `⌊n / 2⌋` times. You may assume that the majority element always exists in the array.", "_readme_examples": { "list": [ - { "content": "```\nInput: nums = [3,2,3]\nOutput: 3\n```" }, - { "content": "```\nInput: nums = [2,2,1,1,1,2,2]\nOutput: 2\n```" } + { + "content": "```\nInput: nums = [3,2,3]\nOutput: 3\n```" + }, + { + "content": "```\nInput: nums = [2,2,1,1,1,2,2]\nOutput: 2\n```" + } ] }, "readme_constraints": "- n == nums.length\n- 1 <= n <= 5 * 10^4\n- -10^9 <= nums[i] <= 10^9", @@ -40,7 +46,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -48,7 +60,25 @@ "name": "test_majority_element", "signature": "(self, nums: list[int], expected: int)", "parametrize": "nums, expected", - "test_cases": "[([3,2,3], 3), ([2,2,1,1,1,2,2], 2), ([1], 1), ([1,1,2], 1), ([2,2,2,1,1], 2), ([5,5,5,5,1,2,3], 5), ([1,2,3,4,4,4,4], 4), ([0,0,0], 0), ([-1,-1,-1,1,1], -1), ([100,100,100,99,99], 100), ([7,7,7,7,7,8,8], 7), ([1,1,1,1,1,1,2,2,2], 1), ([9,9,9,9,8,8,8], 9), ([-5,-5,-5,-4,-4], -5), ([1000,1000,999,999,1000], 1000)]", + "test_cases": { + "list": [ + "([3,2,3], 3)", + "([2,2,1,1,1,2,2], 2)", + "([1], 1)", + "([1,1,2], 1)", + "([2,2,2,1,1], 2)", + "([5,5,5,5,1,2,3], 5)", + "([1,2,3,4,4,4,4], 4)", + "([0,0,0], 0)", + "([-1,-1,-1,1,1], -1)", + "([100,100,100,99,99], 100)", + "([7,7,7,7,7,8,8], 7)", + "([1,1,1,1,1,1,2,2,2], 1)", + "([9,9,9,9,8,8,8], 9)", + "([-5,-5,-5,-4,-4], -5)", + "([1000,1000,999,999,1000], 1000)" + ] + }, "body": " result = run_majority_element(Solution, nums)\n assert_majority_element(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/maximum_depth_of_binary_tree.json b/leetcode_py/cli/resources/leetcode/json/problems/maximum_depth_of_binary_tree.json index 217a983..f0c3e85 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/maximum_depth_of_binary_tree.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/maximum_depth_of_binary_tree.json @@ -5,14 +5,18 @@ "problem_title": "Maximum Depth of Binary Tree", "difficulty": "Easy", "topics": "Tree, Depth-First Search, Breadth-First Search, Binary Tree", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "Given the `root` of a binary tree, return *its maximum depth*.\n\nA binary tree's **maximum depth** is the number of nodes along the longest path from the root node down to the farthest leaf node.", "_readme_examples": { "list": [ { "content": "![Example 1](https://assets.leetcode.com/uploads/2020/11/26/tmp-tree.jpg)\n\n```\nInput: root = [3,9,20,null,null,15,7]\nOutput: 3\n```" }, - { "content": "```\nInput: root = [1,null,2]\nOutput: 2\n```" } + { + "content": "```\nInput: root = [1,null,2]\nOutput: 2\n```" + } ] }, "readme_constraints": "- The number of nodes in the tree is in the range `[0, 10^4]`.\n- `-100 <= Node.val <= 100`", @@ -42,7 +46,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -50,7 +60,25 @@ "name": "test_max_depth", "signature": "(self, root_list: list[int | None], expected: int)", "parametrize": "root_list, expected", - "test_cases": "[([3, 9, 20, None, None, 15, 7], 3), ([1, None, 2], 2), ([], 0), ([1], 1), ([1, 2], 2), ([1, 2, 3], 2), ([1, 2, 3, 4], 3), ([1, None, 2, None, 3], 3), ([1, 2, 3, 4, 5, 6, 7], 3), ([1, 2, None, 4, None, None, None, 8], 3), ([5, 4, 8, 11, None, 13, 4, 7, 2, None, None, None, 1], 4), ([1, 2, 3, None, None, 4, 5, None, None, 6], 4), ([10], 1), ([1, 2, 2, 3, 3, 3, 3], 3), ([0, -1, 1, -2, -1, 0, 2], 3)]", + "test_cases": { + "list": [ + "([3, 9, 20, None, None, 15, 7], 3)", + "([1, None, 2], 2)", + "([], 0)", + "([1], 1)", + "([1, 2], 2)", + "([1, 2, 3], 2)", + "([1, 2, 3, 4], 3)", + "([1, None, 2, None, 3], 3)", + "([1, 2, 3, 4, 5, 6, 7], 3)", + "([1, 2, None, 4, None, None, None, 8], 3)", + "([5, 4, 8, 11, None, 13, 4, 7, 2, None, None, None, 1], 4)", + "([1, 2, 3, None, None, 4, 5, None, None, 6], 4)", + "([10], 1)", + "([1, 2, 2, 3, 3, 3, 3], 3)", + "([0, -1, 1, -2, -1, 0, 2], 3)" + ] + }, "body": " result = run_max_depth(Solution, root_list)\n assert_max_depth(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/maximum_product_subarray.json b/leetcode_py/cli/resources/leetcode/json/problems/maximum_product_subarray.json index 4cd6fc9..9f78e11 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/maximum_product_subarray.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/maximum_product_subarray.json @@ -5,10 +5,10 @@ "problem_title": "Maximum Product Subarray", "difficulty": "Medium", "topics": "Array, Dynamic Programming", - "_tags": { "list": ["grind"] }, - + "_tags": { + "list": ["grind"] + }, "readme_description": "Given an integer array `nums`, find a subarray that has the largest product, and return the product.\n\nThe test cases are generated so that the answer will fit in a **32-bit** integer.", - "_readme_examples": { "list": [ { @@ -19,9 +19,7 @@ } ] }, - "readme_constraints": "- `1 <= nums.length <= 2 * 10^4`\n- `-10 <= nums[i] <= 10`\n- The product of any subarray of `nums` is **guaranteed** to fit in a **32-bit** integer.", - "helpers_imports": "", "helpers_content": "", "helpers_run_name": "max_product", @@ -30,16 +28,13 @@ "helpers_assert_name": "max_product", "helpers_assert_signature": "(result: int, expected: int) -> bool", "helpers_assert_body": " assert result == expected\n return True", - "solution_imports": "", "solution_contents": "", "solution_class_content": "", - "test_imports": "import pytest\nfrom leetcode_py import logged_test\nfrom .helpers import assert_max_product, run_max_product\nfrom .solution import Solution", "test_content": "", "test_class_name": "MaximumProductSubarray", "test_class_content": " def setup_method(self):\n self.solution = Solution()", - "_solution_methods": { "list": [ { @@ -49,23 +44,44 @@ } ] }, - "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, - "_test_methods": { "list": [ { "name": "test_max_product", "signature": "(self, nums: list[int], expected: int)", "parametrize": "nums, expected", - "test_cases": "[([2, 3, -2, 4], 6), ([-2, 0, -1], 0), ([1], 1), ([0], 0), ([-1], -1), ([2, -1, 3], 3), ([-2, -3], 6), ([1, 2, 3, 4], 24), ([-1, -2, -3], 6), ([0, 2], 2), ([3, -1, 4], 4), ([-2, 3, -4], 24), ([2, 3, -2, 4, -1], 48), ([1, 0, -1, 2, 3], 6), ([-3, 0, 1, -2], 1)]", + "test_cases": { + "list": [ + "([2, 3, -2, 4], 6)", + "([-2, 0, -1], 0)", + "([1], 1)", + "([0], 0)", + "([-1], -1)", + "([2, -1, 3], 3)", + "([-2, -3], 6)", + "([1, 2, 3, 4], 24)", + "([-1, -2, -3], 6)", + "([0, 2], 2)", + "([3, -1, 4], 4)", + "([-2, 3, -4], 24)", + "([2, 3, -2, 4, -1], 48)", + "([1, 0, -1, 2, 3], 6)", + "([-3, 0, 1, -2], 1)" + ] + }, "body": " result = run_max_product(Solution, nums)\n assert_max_product(result, expected)" } ] }, - "playground_imports": "from helpers import run_max_product, assert_max_product\nfrom solution import Solution", "playground_setup": "# Example test case\nnums = [2, 3, -2, 4]\nexpected = 6", "playground_run": "result = run_max_product(Solution, nums)\nresult", diff --git a/leetcode_py/cli/resources/leetcode/json/problems/maximum_profit_in_job_scheduling.json b/leetcode_py/cli/resources/leetcode/json/problems/maximum_profit_in_job_scheduling.json index 4a2f47d..1afc054 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/maximum_profit_in_job_scheduling.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/maximum_profit_in_job_scheduling.json @@ -5,7 +5,9 @@ "problem_title": "Maximum Profit in Job Scheduling", "difficulty": "Hard", "topics": "Array, Binary Search, Dynamic Programming, Sorting", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "We have `n` jobs, where every job is scheduled to be done from `startTime[i]` to `endTime[i]`, obtaining a profit of `profit[i]`.\n\nYou're given the `startTime`, `endTime` and `profit` arrays, return the maximum profit you can take such that there are no two jobs in the subset with overlapping time range.\n\nIf you choose a job that ends at time `X` you will be able to start another job that starts at time `X`.", "_readme_examples": { "list": [ @@ -47,7 +49,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -55,7 +63,22 @@ "name": "test_job_scheduling", "signature": "(self, start_time: list[int], end_time: list[int], profit: list[int], expected: int)", "parametrize": "start_time, end_time, profit, expected", - "test_cases": "[([1, 2, 3, 3], [3, 4, 5, 6], [50, 10, 40, 70], 120), ([1, 2, 3, 4, 6], [3, 5, 10, 6, 9], [20, 20, 100, 70, 60], 150), ([1, 1, 1], [2, 3, 4], [5, 6, 4], 6), ([1, 2], [2, 3], [100, 200], 300), ([6, 15, 7, 11, 1, 3, 16, 2], [19, 18, 19, 16, 10, 8, 19, 8], [2, 9, 1, 19, 5, 7, 3, 19], 41), ([1], [2], [100], 100), ([1, 2, 3], [2, 3, 4], [1, 1, 1], 3), ([1, 3, 6, 7, 8, 12], [4, 5, 10, 11, 12, 16], [20, 20, 100, 70, 60, 120], 240), ([1, 4, 6], [3, 5, 7], [50, 10, 40], 100), ([1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [10, 20, 30, 40, 50], 50), ([5, 4, 3, 2, 1], [6, 5, 4, 3, 2], [1, 2, 3, 4, 5], 15), ([1, 1000000000], [2, 1000000001], [1, 10000], 10001)]", + "test_cases": { + "list": [ + "([1, 2, 3, 3], [3, 4, 5, 6], [50, 10, 40, 70], 120)", + "([1, 2, 3, 4, 6], [3, 5, 10, 6, 9], [20, 20, 100, 70, 60], 150)", + "([1, 1, 1], [2, 3, 4], [5, 6, 4], 6)", + "([1, 2], [2, 3], [100, 200], 300)", + "([6, 15, 7, 11, 1, 3, 16, 2], [19, 18, 19, 16, 10, 8, 19, 8], [2, 9, 1, 19, 5, 7, 3, 19], 41)", + "([1], [2], [100], 100)", + "([1, 2, 3], [2, 3, 4], [1, 1, 1], 3)", + "([1, 3, 6, 7, 8, 12], [4, 5, 10, 11, 12, 16], [20, 20, 100, 70, 60, 120], 240)", + "([1, 4, 6], [3, 5, 7], [50, 10, 40], 100)", + "([1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [10, 20, 30, 40, 50], 50)", + "([5, 4, 3, 2, 1], [6, 5, 4, 3, 2], [1, 2, 3, 4, 5], 15)", + "([1, 1000000000], [2, 1000000001], [1, 10000], 10001)" + ] + }, "body": " result = run_job_scheduling(Solution, start_time, end_time, profit)\n assert_job_scheduling(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/maximum_subarray.json b/leetcode_py/cli/resources/leetcode/json/problems/maximum_subarray.json index 9e0611a..fc90f2d 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/maximum_subarray.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/maximum_subarray.json @@ -5,7 +5,9 @@ "problem_title": "Maximum Subarray", "difficulty": "Medium", "topics": "Array, Divide and Conquer, Dynamic Programming", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "Given an integer array `nums`, find the subarray with the largest sum, and return its sum.", "_readme_examples": { "list": [ @@ -47,7 +49,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -55,7 +63,25 @@ "name": "test_max_sub_array", "signature": "(self, nums: list[int], expected: int)", "parametrize": "nums, expected", - "test_cases": "[([-2, 1, -3, 4, -1, 2, 1, -5, 4], 6), ([1], 1), ([5, 4, -1, 7, 8], 23), ([-1], -1), ([-2, -1], -1), ([1, 2, 3, 4, 5], 15), ([-5, -2, -8, -1], -1), ([0], 0), ([0, -1, 0], 0), ([-3, -2, -1, -5], -1), ([2, -1, 2, -1, 2], 4), ([1, -3, 2, 1, -1], 3), ([-2, -3, 4, -1, -2, 1, 5, -3], 7), ([10, -5, 3, -2, 8], 14), ([100], 100)]", + "test_cases": { + "list": [ + "([-2, 1, -3, 4, -1, 2, 1, -5, 4], 6)", + "([1], 1)", + "([5, 4, -1, 7, 8], 23)", + "([-1], -1)", + "([-2, -1], -1)", + "([1, 2, 3, 4, 5], 15)", + "([-5, -2, -8, -1], -1)", + "([0], 0)", + "([0, -1, 0], 0)", + "([-3, -2, -1, -5], -1)", + "([2, -1, 2, -1, 2], 4)", + "([1, -3, 2, 1, -1], 3)", + "([-2, -3, 4, -1, -2, 1, 5, -3], 7)", + "([10, -5, 3, -2, 8], 14)", + "([100], 100)" + ] + }, "body": " result = run_max_sub_array(Solution, nums)\n assert_max_sub_array(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/maximum_width_of_binary_tree.json b/leetcode_py/cli/resources/leetcode/json/problems/maximum_width_of_binary_tree.json index 4d8e2f5..2000ed1 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/maximum_width_of_binary_tree.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/maximum_width_of_binary_tree.json @@ -5,7 +5,9 @@ "problem_title": "Maximum Width of Binary Tree", "difficulty": "Medium", "topics": "Tree, Depth-First Search, Breadth-First Search, Binary Tree", - "_tags": { "list": ["grind"] }, + "_tags": { + "list": ["grind"] + }, "readme_description": "Given the `root` of a binary tree, return *the **maximum width** of the given tree*.\n\nThe **maximum width** of a tree is the maximum **width** among all levels.\n\nThe **width** of one level is defined as the length between the end-nodes (the leftmost and rightmost non-null nodes), where the null nodes between the end-nodes that would be present in a complete binary tree extending down to that level are also counted into the length calculation.\n\nIt is **guaranteed** that the answer will in the range of a **32-bit** signed integer.", "_readme_examples": { "list": [ @@ -47,7 +49,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -55,7 +63,26 @@ "name": "test_width_of_binary_tree", "signature": "(self, root_list: list[int | None], expected: int)", "parametrize": "root_list, expected", - "test_cases": "[([1, 3, 2, 5, 3, None, 9], 4), ([1, 3, 2, 5, None, None, 9, 6, None, 7], 7), ([1, 3, 2, 5], 2), ([1], 1), ([1, 2], 1), ([1, None, 2], 1), ([1, 2, 3], 2), ([1, 2, 3, 4], 2), ([1, 2, 3, 4, 5], 2), ([1, 2, 3, None, None, 4, 5], 2), ([1, 2, 3, None, 4, None, 5], 3), ([1, 2, 3, 4, None, None, 5, 6], 4), ([1, None, 2, None, 3, None, 4], 1), ([1, 2, None, 3, None, 4], 1), ([1, 2, 3, 4, 5, 6, 7], 4), ([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], 8)]", + "test_cases": { + "list": [ + "([1, 3, 2, 5, 3, None, 9], 4)", + "([1, 3, 2, 5, None, None, 9, 6, None, 7], 7)", + "([1, 3, 2, 5], 2)", + "([1], 1)", + "([1, 2], 1)", + "([1, None, 2], 1)", + "([1, 2, 3], 2)", + "([1, 2, 3, 4], 2)", + "([1, 2, 3, 4, 5], 2)", + "([1, 2, 3, None, None, 4, 5], 2)", + "([1, 2, 3, None, 4, None, 5], 3)", + "([1, 2, 3, 4, None, None, 5, 6], 4)", + "([1, None, 2, None, 3, None, 4], 1)", + "([1, 2, None, 3, None, 4], 1)", + "([1, 2, 3, 4, 5, 6, 7], 4)", + "([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], 8)" + ] + }, "body": " result = run_width_of_binary_tree(Solution, root_list)\n assert_width_of_binary_tree(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/merge_intervals.json b/leetcode_py/cli/resources/leetcode/json/problems/merge_intervals.json index 244f3e7..1da118c 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/merge_intervals.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/merge_intervals.json @@ -5,7 +5,9 @@ "problem_title": "Merge Intervals", "difficulty": "Medium", "topics": "Array, Sorting", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "Given an array of `intervals` where `intervals[i] = [starti, endi]`, merge all overlapping intervals, and return an array of the non-overlapping intervals that cover all the intervals in the input.", "_readme_examples": { "list": [ @@ -47,7 +49,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -55,7 +63,22 @@ "name": "test_merge", "signature": "(self, intervals: list[list[int]], expected: list[list[int]])", "parametrize": "intervals, expected", - "test_cases": "[([[1,3],[2,6],[8,10],[15,18]], [[1,6],[8,10],[15,18]]), ([[1,4],[4,5]], [[1,5]]), ([[4,7],[1,4]], [[1,7]]), ([[1,3]], [[1,3]]), ([[1,4],[2,3]], [[1,4]]), ([[1,2],[3,4],[5,6]], [[1,2],[3,4],[5,6]]), ([[0,0]], [[0,0]]), ([[1,10],[2,3],[4,5],[6,7],[8,9]], [[1,10]]), ([[1,3],[2,6],[8,10],[9,12],[15,18]], [[1,6],[8,12],[15,18]]), ([[2,3],[4,5],[6,7],[8,9],[1,10]], [[1,10]]), ([[1,4],[0,4]], [[0,4]]), ([[1,4],[0,0],[3,5]], [[0,0],[1,5]])]", + "test_cases": { + "list": [ + "([[1,3],[2,6],[8,10],[15,18]], [[1,6],[8,10],[15,18]])", + "([[1,4],[4,5]], [[1,5]])", + "([[4,7],[1,4]], [[1,7]])", + "([[1,3]], [[1,3]])", + "([[1,4],[2,3]], [[1,4]])", + "([[1,2],[3,4],[5,6]], [[1,2],[3,4],[5,6]])", + "([[0,0]], [[0,0]])", + "([[1,10],[2,3],[4,5],[6,7],[8,9]], [[1,10]])", + "([[1,3],[2,6],[8,10],[9,12],[15,18]], [[1,6],[8,12],[15,18]])", + "([[2,3],[4,5],[6,7],[8,9],[1,10]], [[1,10]])", + "([[1,4],[0,4]], [[0,4]])", + "([[1,4],[0,0],[3,5]], [[0,0],[1,5]])" + ] + }, "body": " result = run_merge(Solution, intervals)\n assert_merge(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/merge_k_sorted_lists.json b/leetcode_py/cli/resources/leetcode/json/problems/merge_k_sorted_lists.json index 4c58547..2a1963a 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/merge_k_sorted_lists.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/merge_k_sorted_lists.json @@ -5,15 +5,21 @@ "problem_title": "Merge k Sorted Lists", "difficulty": "Hard", "topics": "Linked List, Divide and Conquer, Heap (Priority Queue), Merge Sort", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "You are given an array of `k` linked-lists `lists`, each linked-list is sorted in ascending order.\n\n*Merge all the linked-lists into one sorted linked-list and return it.*", "_readme_examples": { "list": [ { "content": "```\nInput: lists = [[1,4,5],[1,3,4],[2,6]]\nOutput: [1,1,2,3,4,4,5,6]\n```\n**Explanation:** The linked-lists are:\n```\n[\n 1->4->5,\n 1->3->4,\n 2->6\n]\n```\nmerging them into one sorted linked list:\n```\n1->1->2->3->4->4->5->6\n```" }, - { "content": "```\nInput: lists = []\nOutput: []\n```" }, - { "content": "```\nInput: lists = [[]]\nOutput: []\n```" } + { + "content": "```\nInput: lists = []\nOutput: []\n```" + }, + { + "content": "```\nInput: lists = [[]]\nOutput: []\n```" + } ] }, "readme_constraints": "- `k == lists.length`\n- `0 <= k <= 10^4`\n- `0 <= lists[i].length <= 500`\n- `-10^4 <= lists[i][j] <= 10^4`\n- `lists[i]` is sorted in ascending order.\n- The sum of `lists[i].length` will not exceed `10^4`.", @@ -43,7 +49,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -51,7 +63,25 @@ "name": "test_merge_k_lists", "signature": "(self, lists_data: list[list[int]], expected_data: list[int])", "parametrize": "lists_data, expected_data", - "test_cases": "[([[1, 4, 5], [1, 3, 4], [2, 6]], [1, 1, 2, 3, 4, 4, 5, 6]), ([], []), ([[]], []), ([[1]], [1]), ([[1, 2], [3, 4]], [1, 2, 3, 4]), ([[5], [1, 3], [2, 4, 6]], [1, 2, 3, 4, 5, 6]), ([[-1, 0, 1], [-2, 2]], [-2, -1, 0, 1, 2]), ([[1, 1, 1], [2, 2, 2]], [1, 1, 1, 2, 2, 2]), ([[], [1], []], [1]), ([[0, 0, 0], [1, 1, 1]], [0, 0, 0, 1, 1, 1]), ([[10], [5], [1]], [1, 5, 10]), ([[1, 2, 3, 4, 5]], [1, 2, 3, 4, 5]), ([[-10, -5], [-8, -3], [-6, -1]], [-10, -8, -6, -5, -3, -1]), ([[100]], [100]), ([[1, 3, 5], [2, 4, 6], [7, 8, 9]], [1, 2, 3, 4, 5, 6, 7, 8, 9])]", + "test_cases": { + "list": [ + "([[1, 4, 5], [1, 3, 4], [2, 6]], [1, 1, 2, 3, 4, 4, 5, 6])", + "([], [])", + "([[]], [])", + "([[1]], [1])", + "([[1, 2], [3, 4]], [1, 2, 3, 4])", + "([[5], [1, 3], [2, 4, 6]], [1, 2, 3, 4, 5, 6])", + "([[-1, 0, 1], [-2, 2]], [-2, -1, 0, 1, 2])", + "([[1, 1, 1], [2, 2, 2]], [1, 1, 1, 2, 2, 2])", + "([[], [1], []], [1])", + "([[0, 0, 0], [1, 1, 1]], [0, 0, 0, 1, 1, 1])", + "([[10], [5], [1]], [1, 5, 10])", + "([[1, 2, 3, 4, 5]], [1, 2, 3, 4, 5])", + "([[-10, -5], [-8, -3], [-6, -1]], [-10, -8, -6, -5, -3, -1])", + "([[100]], [100])", + "([[1, 3, 5], [2, 4, 6], [7, 8, 9]], [1, 2, 3, 4, 5, 6, 7, 8, 9])" + ] + }, "body": " result = run_merge_k_lists(Solution, lists_data)\n assert_merge_k_lists(result, expected_data)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/merge_two_sorted_lists.json b/leetcode_py/cli/resources/leetcode/json/problems/merge_two_sorted_lists.json index 45a89ce..129536a 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/merge_two_sorted_lists.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/merge_two_sorted_lists.json @@ -5,15 +5,21 @@ "problem_title": "Merge Two Sorted Lists", "difficulty": "Easy", "topics": "Linked List, Recursion", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "You are given the heads of two sorted linked lists `list1` and `list2`.\n\nMerge the two lists into one **sorted** list. The list should be made by splicing together the nodes of the first two lists.\n\nReturn *the head of the merged linked list*.", "_readme_examples": { "list": [ { "content": "![Example 1](https://assets.leetcode.com/uploads/2020/10/03/merge_ex1.jpg)\n\n```\nInput: list1 = [1,2,4], list2 = [1,3,4]\nOutput: [1,1,2,3,4,4]\n```" }, - { "content": "```\nInput: list1 = [], list2 = []\nOutput: []\n```" }, - { "content": "```\nInput: list1 = [], list2 = [0]\nOutput: [0]\n```" } + { + "content": "```\nInput: list1 = [], list2 = []\nOutput: []\n```" + }, + { + "content": "```\nInput: list1 = [], list2 = [0]\nOutput: [0]\n```" + } ] }, "readme_constraints": "- The number of nodes in both lists is in the range `[0, 50]`.\n- `-100 <= Node.val <= 100`\n- Both `list1` and `list2` are sorted in **non-decreasing** order.", @@ -43,7 +49,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -51,7 +63,24 @@ "name": "test_merge_two_lists", "signature": "(self, list1_vals: list[int], list2_vals: list[int], expected_vals: list[int])", "parametrize": "list1_vals, list2_vals, expected_vals", - "test_cases": "[([1, 2, 4], [1, 3, 4], [1, 1, 2, 3, 4, 4]), ([], [], []), ([], [0], [0]), ([1], [2], [1, 2]), ([2], [1], [1, 2]), ([1, 3, 5], [2, 4, 6], [1, 2, 3, 4, 5, 6]), ([1, 1, 1], [2, 2, 2], [1, 1, 1, 2, 2, 2]), ([0], [], [0]), ([1, 2, 3], [], [1, 2, 3]), ([5], [1, 2, 3, 4], [1, 2, 3, 4, 5]), ([-1, 0, 1], [-2, 2, 3], [-2, -1, 0, 1, 2, 3]), ([1, 5, 9], [2, 6, 8], [1, 2, 5, 6, 8, 9]), ([10, 20, 30], [15, 25, 35], [10, 15, 20, 25, 30, 35]), ([1, 1], [1, 1], [1, 1, 1, 1])]", + "test_cases": { + "list": [ + "([1, 2, 4], [1, 3, 4], [1, 1, 2, 3, 4, 4])", + "([], [], [])", + "([], [0], [0])", + "([1], [2], [1, 2])", + "([2], [1], [1, 2])", + "([1, 3, 5], [2, 4, 6], [1, 2, 3, 4, 5, 6])", + "([1, 1, 1], [2, 2, 2], [1, 1, 1, 2, 2, 2])", + "([0], [], [0])", + "([1, 2, 3], [], [1, 2, 3])", + "([5], [1, 2, 3, 4], [1, 2, 3, 4, 5])", + "([-1, 0, 1], [-2, 2, 3], [-2, -1, 0, 1, 2, 3])", + "([1, 5, 9], [2, 6, 8], [1, 2, 5, 6, 8, 9])", + "([10, 20, 30], [15, 25, 35], [10, 15, 20, 25, 30, 35])", + "([1, 1], [1, 1], [1, 1, 1, 1])" + ] + }, "body": " result = run_merge_two_lists(Solution, list1_vals, list2_vals)\n assert_merge_two_lists(result, expected_vals)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/middle_of_the_linked_list.json b/leetcode_py/cli/resources/leetcode/json/problems/middle_of_the_linked_list.json index 4e333f7..3eb9de6 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/middle_of_the_linked_list.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/middle_of_the_linked_list.json @@ -5,7 +5,9 @@ "problem_title": "Middle of the Linked List", "difficulty": "Easy", "topics": "Linked List, Two Pointers", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "Given the `head` of a singly linked list, return *the middle node of the linked list*.\n\nIf there are two middle nodes, return **the second middle** node.", "_readme_examples": { "list": [ @@ -44,7 +46,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -52,7 +60,24 @@ "name": "test_middle_node", "signature": "(self, head_list: list[int], expected_list: list[int])", "parametrize": "head_list, expected_list", - "test_cases": "[([1, 2, 3, 4, 5], [3, 4, 5]), ([1, 2, 3, 4, 5, 6], [4, 5, 6]), ([1], [1]), ([1, 2], [2]), ([1, 2, 3], [2, 3]), ([1, 2, 3, 4], [3, 4]), ([10, 20, 30, 40, 50, 60, 70], [40, 50, 60, 70]), ([5, 10], [10]), ([1, 3, 5, 7, 9], [5, 7, 9]), ([2, 4, 6, 8, 10, 12], [8, 10, 12]), ([100], [100]), ([7, 14, 21], [14, 21]), ([11, 22, 33, 44], [33, 44]), ([1, 1, 1, 1, 1], [1, 1, 1])]", + "test_cases": { + "list": [ + "([1, 2, 3, 4, 5], [3, 4, 5])", + "([1, 2, 3, 4, 5, 6], [4, 5, 6])", + "([1], [1])", + "([1, 2], [2])", + "([1, 2, 3], [2, 3])", + "([1, 2, 3, 4], [3, 4])", + "([10, 20, 30, 40, 50, 60, 70], [40, 50, 60, 70])", + "([5, 10], [10])", + "([1, 3, 5, 7, 9], [5, 7, 9])", + "([2, 4, 6, 8, 10, 12], [8, 10, 12])", + "([100], [100])", + "([7, 14, 21], [14, 21])", + "([11, 22, 33, 44], [33, 44])", + "([1, 1, 1, 1, 1], [1, 1, 1])" + ] + }, "body": " result = run_middle_node(Solution, head_list)\n assert_middle_node(result, expected_list)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/min_stack.json b/leetcode_py/cli/resources/leetcode/json/problems/min_stack.json index 739f13e..54fb716 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/min_stack.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/min_stack.json @@ -5,7 +5,9 @@ "problem_title": "Min Stack", "difficulty": "Medium", "topics": "Stack, Design", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.\n\nImplement the `MinStack` class:\n\n- `MinStack()` initializes the stack object.\n- `void push(int val)` pushes the element `val` onto the stack.\n- `void pop()` removes the element on the top of the stack.\n- `int top()` gets the top element of the stack.\n- `int getMin()` retrieves the minimum element in the stack.\n\nYou must implement a solution with `O(1)` time complexity for each function.", "_readme_examples": { "list": [ @@ -60,14 +62,31 @@ } ] }, - "_test_helper_methods": { "list": [] }, + "_test_helper_methods": { + "list": [] + }, "_test_methods": { "list": [ { "name": "test_min_stack", "signature": "(self, operations: list[str], inputs: list[list[int]], expected: list[int | None])", "parametrize": "operations, inputs, expected", - "test_cases": "[(['MinStack', 'push', 'push', 'push', 'getMin', 'pop', 'top', 'getMin'], [[], [-2], [0], [-3], [], [], [], []], [None, None, None, None, -3, None, 0, -2]), (['MinStack', 'push', 'top', 'getMin', 'pop'], [[], [5], [], [], []], [None, None, 5, 5, None]), (['MinStack', 'push', 'push', 'push', 'getMin', 'pop', 'getMin', 'pop', 'getMin'], [[], [1], [1], [2], [], [], [], [], []], [None, None, None, None, 1, None, 1, None, 1]), (['MinStack', 'push', 'getMin', 'top'], [[], [0], [], []], [None, None, 0, 0]), (['MinStack', 'push', 'push', 'getMin', 'push', 'getMin', 'pop', 'getMin'], [[], [2], [1], [], [0], [], [], []], [None, None, None, 1, None, 0, None, 1]), (['MinStack', 'push', 'push', 'push', 'top', 'getMin', 'pop', 'pop', 'top', 'getMin'], [[], [3], [1], [4], [], [], [], [], [], []], [None, None, None, None, 4, 1, None, None, 3, 3]), (['MinStack', 'push', 'push', 'getMin', 'pop', 'push', 'getMin'], [[], [-1], [-2], [], [], [0], []], [None, None, None, -2, None, None, -1]), (['MinStack', 'push', 'push', 'push', 'push', 'getMin', 'pop', 'pop', 'getMin'], [[], [5], [3], [7], [2], [], [], [], []], [None, None, None, None, None, 2, None, None, 3]), (['MinStack', 'push', 'push', 'push', 'getMin', 'pop', 'getMin', 'pop', 'getMin', 'pop', 'push', 'getMin'], [[], [10], [5], [15], [], [], [], [], [], [], [8], []], [None, None, None, None, 5, None, 5, None, 10, None, None, 8]), (['MinStack', 'push', 'push', 'push', 'push', 'push', 'getMin', 'pop', 'getMin', 'pop', 'getMin'], [[], [1], [2], [0], [3], [4], [], [], [], [], []], [None, None, None, None, None, None, 0, None, 0, None, 0]), (['MinStack', 'push', 'getMin', 'push', 'getMin', 'push', 'getMin', 'top'], [[], [2147483647], [], [-2147483648], [], [0], [], []], [None, None, 2147483647, None, -2147483648, None, -2147483648, 0]), (['MinStack', 'push', 'push', 'push', 'push', 'push', 'top', 'getMin', 'pop', 'top', 'getMin', 'pop', 'getMin'], [[], [1], [1], [1], [1], [1], [], [], [], [], [], [], []], [None, None, None, None, None, None, 1, 1, None, 1, 1, None, 1])]", + "test_cases": { + "list": [ + "(['MinStack', 'push', 'push', 'push', 'getMin', 'pop', 'top', 'getMin'], [[], [-2], [0], [-3], [], [], [], []], [None, None, None, None, -3, None, 0, -2])", + "(['MinStack', 'push', 'top', 'getMin', 'pop'], [[], [5], [], [], []], [None, None, 5, 5, None])", + "(['MinStack', 'push', 'push', 'push', 'getMin', 'pop', 'getMin', 'pop', 'getMin'], [[], [1], [1], [2], [], [], [], [], []], [None, None, None, None, 1, None, 1, None, 1])", + "(['MinStack', 'push', 'getMin', 'top'], [[], [0], [], []], [None, None, 0, 0])", + "(['MinStack', 'push', 'push', 'getMin', 'push', 'getMin', 'pop', 'getMin'], [[], [2], [1], [], [0], [], [], []], [None, None, None, 1, None, 0, None, 1])", + "(['MinStack', 'push', 'push', 'push', 'top', 'getMin', 'pop', 'pop', 'top', 'getMin'], [[], [3], [1], [4], [], [], [], [], [], []], [None, None, None, None, 4, 1, None, None, 3, 3])", + "(['MinStack', 'push', 'push', 'getMin', 'pop', 'push', 'getMin'], [[], [-1], [-2], [], [], [0], []], [None, None, None, -2, None, None, -1])", + "(['MinStack', 'push', 'push', 'push', 'push', 'getMin', 'pop', 'pop', 'getMin'], [[], [5], [3], [7], [2], [], [], [], []], [None, None, None, None, None, 2, None, None, 3])", + "(['MinStack', 'push', 'push', 'push', 'getMin', 'pop', 'getMin', 'pop', 'getMin', 'pop', 'push', 'getMin'], [[], [10], [5], [15], [], [], [], [], [], [], [8], []], [None, None, None, None, 5, None, 5, None, 10, None, None, 8])", + "(['MinStack', 'push', 'push', 'push', 'push', 'push', 'getMin', 'pop', 'getMin', 'pop', 'getMin'], [[], [1], [2], [0], [3], [4], [], [], [], [], []], [None, None, None, None, None, None, 0, None, 0, None, 0])", + "(['MinStack', 'push', 'getMin', 'push', 'getMin', 'push', 'getMin', 'top'], [[], [2147483647], [], [-2147483648], [], [0], [], []], [None, None, 2147483647, None, -2147483648, None, -2147483648, 0])", + "(['MinStack', 'push', 'push', 'push', 'push', 'push', 'top', 'getMin', 'pop', 'top', 'getMin', 'pop', 'getMin'], [[], [1], [1], [1], [1], [1], [], [], [], [], [], [], []], [None, None, None, None, None, None, 1, 1, None, 1, 1, None, 1])" + ] + }, "body": " result = run_min_stack_operations(MinStack, operations, inputs)\n assert_min_stack_operations(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/minimum_height_trees.json b/leetcode_py/cli/resources/leetcode/json/problems/minimum_height_trees.json index c4d3133..4381679 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/minimum_height_trees.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/minimum_height_trees.json @@ -5,7 +5,9 @@ "problem_title": "Minimum Height Trees", "difficulty": "Medium", "topics": "Depth-First Search, Breadth-First Search, Graph, Topological Sort", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "A tree is an undirected graph in which any two vertices are connected by *exactly* one path. In other words, any connected graph without simple cycles is a tree.\n\nGiven a tree of `n` nodes labelled from `0` to `n - 1`, and an array of `n - 1` `edges` where `edges[i] = [ai, bi]` indicates that there is an undirected edge between the two nodes `ai` and `bi` in the tree, you can choose any node of the tree as the root. When you select a node `x` as the root, the result tree has height `h`. Among all possible rooted trees, those with minimum height (i.e. `min(h)`) are called **minimum height trees** (MHTs).\n\nReturn *a list of all **MHTs'** root labels*. You can return the answer in **any order**.\n\nThe **height** of a rooted tree is the number of edges on the longest downward path between the root and a leaf.", "_readme_examples": { "list": [ @@ -44,7 +46,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -52,7 +60,22 @@ "name": "test_find_min_height_trees", "signature": "(self, n: int, edges: list[list[int]], expected: list[int])", "parametrize": "n, edges, expected", - "test_cases": "[(4, [[1, 0], [1, 2], [1, 3]], [1]), (6, [[3, 0], [3, 1], [3, 2], [3, 4], [5, 4]], [3, 4]), (1, [], [0]), (2, [[0, 1]], [0, 1]), (3, [[0, 1], [1, 2]], [1]), (5, [[0, 1], [1, 2], [2, 3], [3, 4]], [2]), (7, [[0, 1], [1, 2], [1, 3], [2, 4], [3, 5], [4, 6]], [1, 2]), (6, [[0, 3], [1, 3], [2, 3], [4, 3], [5, 4]], [3, 4]), (10, [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]], [4, 5]), (8, [[0, 1], [1, 2], [2, 3], [0, 4], [4, 5], [5, 6], [6, 7]], [0, 4]), (9, [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [4, 8]], [0, 1]), (11, [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]], [5])]", + "test_cases": { + "list": [ + "(4, [[1, 0], [1, 2], [1, 3]], [1])", + "(6, [[3, 0], [3, 1], [3, 2], [3, 4], [5, 4]], [3, 4])", + "(1, [], [0])", + "(2, [[0, 1]], [0, 1])", + "(3, [[0, 1], [1, 2]], [1])", + "(5, [[0, 1], [1, 2], [2, 3], [3, 4]], [2])", + "(7, [[0, 1], [1, 2], [1, 3], [2, 4], [3, 5], [4, 6]], [1, 2])", + "(6, [[0, 3], [1, 3], [2, 3], [4, 3], [5, 4]], [3, 4])", + "(10, [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]], [4, 5])", + "(8, [[0, 1], [1, 2], [2, 3], [0, 4], [4, 5], [5, 6], [6, 7]], [0, 4])", + "(9, [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [4, 8]], [0, 1])", + "(11, [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]], [5])" + ] + }, "body": " result = run_find_min_height_trees(Solution, n, edges)\n assert_find_min_height_trees(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/minimum_window_substring.json b/leetcode_py/cli/resources/leetcode/json/problems/minimum_window_substring.json index efaef29..a79fe50 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/minimum_window_substring.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/minimum_window_substring.json @@ -5,7 +5,9 @@ "problem_title": "Minimum Window Substring", "difficulty": "Hard", "topics": "Hash Table, String, Sliding Window", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "Given two strings `s` and `t` of lengths `m` and `n` respectively, return the **minimum window substring** of `s` such that every character in `t` (including duplicates) is included in the window. If there is no such substring, return the empty string `\"\"`.\n\nThe testcases will be generated such that the answer is unique.", "_readme_examples": { "list": [ @@ -47,7 +49,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -55,7 +63,21 @@ "name": "test_min_window", "signature": "(self, s: str, t: str, expected: str)", "parametrize": "s, t, expected", - "test_cases": "[(\"ADOBECODEBANC\", \"ABC\", \"BANC\"), (\"a\", \"a\", \"a\"), (\"a\", \"aa\", \"\"), (\"ab\", \"b\", \"b\"), (\"abc\", \"cba\", \"abc\"), (\"aa\", \"aa\", \"aa\"), (\"a\", \"b\", \"\"), (\"ab\", \"a\", \"a\"), (\"bba\", \"ab\", \"ba\"), (\"acbbaca\", \"aba\", \"baca\"), (\"cabwefgewcwaefgcf\", \"cae\", \"cwae\")]", + "test_cases": { + "list": [ + "(\"ADOBECODEBANC\", \"ABC\", \"BANC\")", + "(\"a\", \"a\", \"a\")", + "(\"a\", \"aa\", \"\")", + "(\"ab\", \"b\", \"b\")", + "(\"abc\", \"cba\", \"abc\")", + "(\"aa\", \"aa\", \"aa\")", + "(\"a\", \"b\", \"\")", + "(\"ab\", \"a\", \"a\")", + "(\"bba\", \"ab\", \"ba\")", + "(\"acbbaca\", \"aba\", \"baca\")", + "(\"cabwefgewcwaefgcf\", \"cae\", \"cwae\")" + ] + }, "body": " result = run_min_window(Solution, s, t)\n assert_min_window(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/next_permutation.json b/leetcode_py/cli/resources/leetcode/json/problems/next_permutation.json index dfeb02d..51c706d 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/next_permutation.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/next_permutation.json @@ -5,20 +5,24 @@ "problem_title": "Next Permutation", "difficulty": "Medium", "topics": "Array, Two Pointers", - "_tags": { "list": ["grind"] }, - + "_tags": { + "list": ["grind"] + }, "readme_description": "A **permutation** of an array of integers is an arrangement of its members into a sequence or linear order.\n\n- For example, for `arr = [1,2,3]`, the following are all the permutations of `arr`: `[1,2,3], [1,3,2], [2, 1, 3], [2, 3, 1], [3,1,2], [3,2,1]`.\n\nThe **next permutation** of an array of integers is the next lexicographically greater permutation of its integer. More formally, if all the permutations of the array are sorted in one container according to their lexicographical order, then the **next permutation** of that array is the permutation that follows it in the sorted container. If such arrangement is not possible, the array must be rearranged as the lowest possible order (i.e., sorted in ascending order).\n\n- For example, the next permutation of `arr = [1,2,3]` is `[1,3,2]`.\n- Similarly, the next permutation of `arr = [2,3,1]` is `[3,1,2]`.\n- While the next permutation of `arr = [3,2,1]` is `[1,2,3]` because `[3,2,1]` does not have a lexicographical larger rearrangement.\n\nGiven an array of integers `nums`, find the next permutation of `nums`.\n\nThe replacement must be **in place** and use only constant extra memory.", - "_readme_examples": { "list": [ - { "content": "```\nInput: nums = [1,2,3]\nOutput: [1,3,2]\n```" }, - { "content": "```\nInput: nums = [3,2,1]\nOutput: [1,2,3]\n```" }, - { "content": "```\nInput: nums = [1,1,5]\nOutput: [1,5,1]\n```" } + { + "content": "```\nInput: nums = [1,2,3]\nOutput: [1,3,2]\n```" + }, + { + "content": "```\nInput: nums = [3,2,1]\nOutput: [1,2,3]\n```" + }, + { + "content": "```\nInput: nums = [1,1,5]\nOutput: [1,5,1]\n```" + } ] }, - "readme_constraints": "- `1 <= nums.length <= 100`\n- `0 <= nums[i] <= 100`", - "helpers_imports": "", "helpers_content": "", "helpers_run_name": "next_permutation", @@ -27,16 +31,13 @@ "helpers_assert_name": "next_permutation", "helpers_assert_signature": "(result: list[int], expected: list[int]) -> bool", "helpers_assert_body": " assert result == expected\n return True", - "solution_imports": "", "solution_contents": "", "solution_class_content": "", - "test_imports": "import pytest\nfrom leetcode_py import logged_test\nfrom .helpers import assert_next_permutation, run_next_permutation\nfrom .solution import Solution", "test_content": "", "test_class_name": "NextPermutation", "test_class_content": " def setup_method(self):\n self.solution = Solution()", - "_solution_methods": { "list": [ { @@ -46,23 +47,44 @@ } ] }, - "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, - "_test_methods": { "list": [ { "name": "test_next_permutation", "signature": "(self, nums: list[int], expected: list[int])", "parametrize": "nums, expected", - "test_cases": "[([1, 2, 3], [1, 3, 2]), ([3, 2, 1], [1, 2, 3]), ([1, 1, 5], [1, 5, 1]), ([1], [1]), ([1, 2], [2, 1]), ([2, 1], [1, 2]), ([1, 3, 2], [2, 1, 3]), ([2, 3, 1], [3, 1, 2]), ([1, 2, 3, 4], [1, 2, 4, 3]), ([4, 3, 2, 1], [1, 2, 3, 4]), ([1, 1, 1], [1, 1, 1]), ([1, 2, 1], [2, 1, 1]), ([5, 4, 7, 5, 3, 2], [5, 5, 2, 3, 4, 7]), ([1, 3, 2, 1], [2, 1, 1, 3]), ([2, 1, 3], [2, 3, 1])]", + "test_cases": { + "list": [ + "([1, 2, 3], [1, 3, 2])", + "([3, 2, 1], [1, 2, 3])", + "([1, 1, 5], [1, 5, 1])", + "([1], [1])", + "([1, 2], [2, 1])", + "([2, 1], [1, 2])", + "([1, 3, 2], [2, 1, 3])", + "([2, 3, 1], [3, 1, 2])", + "([1, 2, 3, 4], [1, 2, 4, 3])", + "([4, 3, 2, 1], [1, 2, 3, 4])", + "([1, 1, 1], [1, 1, 1])", + "([1, 2, 1], [2, 1, 1])", + "([5, 4, 7, 5, 3, 2], [5, 5, 2, 3, 4, 7])", + "([1, 3, 2, 1], [2, 1, 1, 3])", + "([2, 1, 3], [2, 3, 1])" + ] + }, "body": " result = run_next_permutation(Solution, nums)\n assert_next_permutation(result, expected)" } ] }, - "playground_imports": "from helpers import run_next_permutation, assert_next_permutation\nfrom solution import Solution", "playground_setup": "# Example test case\nnums = [1, 2, 3]\nexpected = [1, 3, 2]", "playground_run": "result = run_next_permutation(Solution, nums)\nresult", diff --git a/leetcode_py/cli/resources/leetcode/json/problems/number_of_islands.json b/leetcode_py/cli/resources/leetcode/json/problems/number_of_islands.json index edf3ea2..f712c04 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/number_of_islands.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/number_of_islands.json @@ -5,7 +5,9 @@ "problem_title": "Number of Islands", "difficulty": "Medium", "topics": "Array, Depth-First Search, Breadth-First Search, Union Find, Matrix", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "Given an `m x n` 2D binary grid `grid` which represents a map of `'1'`s (land) and `'0'`s (water), return *the number of islands*.\n\nAn **island** is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are all surrounded by water.", "_readme_examples": { "list": [ @@ -44,7 +46,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -52,7 +60,24 @@ "name": "test_num_islands", "signature": "(self, grid: list[list[str]], expected: int)", "parametrize": "grid, expected", - "test_cases": "[([[\"1\", \"1\", \"1\", \"1\", \"0\"], [\"1\", \"1\", \"0\", \"1\", \"0\"], [\"1\", \"1\", \"0\", \"0\", \"0\"], [\"0\", \"0\", \"0\", \"0\", \"0\"]], 1), ([[\"1\", \"1\", \"0\", \"0\", \"0\"], [\"1\", \"1\", \"0\", \"0\", \"0\"], [\"0\", \"0\", \"1\", \"0\", \"0\"], [\"0\", \"0\", \"0\", \"1\", \"1\"]], 3), ([[\"1\", \"0\", \"1\", \"1\", \"1\"], [\"1\", \"0\", \"1\", \"0\", \"1\"], [\"1\", \"1\", \"1\", \"0\", \"1\"]], 1), ([[\"0\", \"0\", \"0\", \"0\", \"0\"], [\"0\", \"0\", \"0\", \"0\", \"0\"], [\"0\", \"0\", \"0\", \"0\", \"0\"]], 0), ([[\"1\", \"1\", \"1\"], [\"0\", \"1\", \"0\"], [\"1\", \"1\", \"1\"]], 1), ([[\"1\"]], 1), ([[\"0\"]], 0), ([[\"1\", \"0\"], [\"0\", \"1\"]], 2), ([[\"1\", \"1\"], [\"1\", \"1\"]], 1), ([[\"1\", \"0\", \"1\"], [\"0\", \"1\", \"0\"], [\"1\", \"0\", \"1\"]], 5), ([[\"1\", \"1\", \"0\"], [\"0\", \"0\", \"1\"], [\"0\", \"1\", \"1\"]], 2), ([[\"1\", \"0\", \"0\", \"1\"], [\"0\", \"1\", \"1\", \"0\"], [\"0\", \"1\", \"1\", \"0\"], [\"1\", \"0\", \"0\", \"1\"]], 5), ([[\"0\", \"1\", \"0\"], [\"1\", \"0\", \"1\"], [\"0\", \"1\", \"0\"]], 4), ([[\"1\", \"1\", \"1\", \"1\"], [\"1\", \"0\", \"0\", \"1\"], [\"1\", \"1\", \"1\", \"1\"]], 1)]", + "test_cases": { + "list": [ + "([[\"1\", \"1\", \"1\", \"1\", \"0\"], [\"1\", \"1\", \"0\", \"1\", \"0\"], [\"1\", \"1\", \"0\", \"0\", \"0\"], [\"0\", \"0\", \"0\", \"0\", \"0\"]], 1)", + "([[\"1\", \"1\", \"0\", \"0\", \"0\"], [\"1\", \"1\", \"0\", \"0\", \"0\"], [\"0\", \"0\", \"1\", \"0\", \"0\"], [\"0\", \"0\", \"0\", \"1\", \"1\"]], 3)", + "([[\"1\", \"0\", \"1\", \"1\", \"1\"], [\"1\", \"0\", \"1\", \"0\", \"1\"], [\"1\", \"1\", \"1\", \"0\", \"1\"]], 1)", + "([[\"0\", \"0\", \"0\", \"0\", \"0\"], [\"0\", \"0\", \"0\", \"0\", \"0\"], [\"0\", \"0\", \"0\", \"0\", \"0\"]], 0)", + "([[\"1\", \"1\", \"1\"], [\"0\", \"1\", \"0\"], [\"1\", \"1\", \"1\"]], 1)", + "([[\"1\"]], 1)", + "([[\"0\"]], 0)", + "([[\"1\", \"0\"], [\"0\", \"1\"]], 2)", + "([[\"1\", \"1\"], [\"1\", \"1\"]], 1)", + "([[\"1\", \"0\", \"1\"], [\"0\", \"1\", \"0\"], [\"1\", \"0\", \"1\"]], 5)", + "([[\"1\", \"1\", \"0\"], [\"0\", \"0\", \"1\"], [\"0\", \"1\", \"1\"]], 2)", + "([[\"1\", \"0\", \"0\", \"1\"], [\"0\", \"1\", \"1\", \"0\"], [\"0\", \"1\", \"1\", \"0\"], [\"1\", \"0\", \"0\", \"1\"]], 5)", + "([[\"0\", \"1\", \"0\"], [\"1\", \"0\", \"1\"], [\"0\", \"1\", \"0\"]], 4)", + "([[\"1\", \"1\", \"1\", \"1\"], [\"1\", \"0\", \"0\", \"1\"], [\"1\", \"1\", \"1\", \"1\"]], 1)" + ] + }, "body": " result = run_num_islands(Solution, grid)\n assert_num_islands(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/odd_even_linked_list.json b/leetcode_py/cli/resources/leetcode/json/problems/odd_even_linked_list.json index 5284b18..26147af 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/odd_even_linked_list.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/odd_even_linked_list.json @@ -5,7 +5,9 @@ "problem_title": "Odd Even Linked List", "difficulty": "Medium", "topics": "Linked List", - "_tags": { "list": ["grind"] }, + "_tags": { + "list": ["grind"] + }, "readme_description": "Given the `head` of a singly linked list, group all the nodes with odd indices together followed by the nodes with even indices, and return *the reordered list*.\n\nThe **first** node is considered **odd**, and the **second** node is **even**, and so on.\n\nNote that the relative order inside both the even and odd groups should remain as it was in the input.\n\nYou must solve the problem in `O(1)` extra space complexity and `O(n)` time complexity.", "_readme_examples": { "list": [ @@ -44,7 +46,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -52,7 +60,26 @@ "name": "test_odd_even_list", "signature": "(self, head_list: list[int], expected: list[int])", "parametrize": "head_list, expected", - "test_cases": "[([1, 2, 3, 4, 5], [1, 3, 5, 2, 4]), ([2, 1, 3, 5, 6, 4, 7], [2, 3, 6, 7, 1, 5, 4]), ([], []), ([1], [1]), ([1, 2], [1, 2]), ([1, 2, 3], [1, 3, 2]), ([1, 2, 3, 4], [1, 3, 2, 4]), ([5, 4, 3, 2, 1], [5, 3, 1, 4, 2]), ([10, 20, 30, 40, 50, 60], [10, 30, 50, 20, 40, 60]), ([7, 6, 5, 4, 3, 2, 1], [7, 5, 3, 1, 6, 4, 2]), ([100], [100]), ([1, 3, 5, 7, 9], [1, 5, 9, 3, 7]), ([2, 4, 6, 8], [2, 6, 4, 8]), ([9, 8, 7, 6, 5, 4, 3, 2, 1], [9, 7, 5, 3, 1, 8, 6, 4, 2]), ([1, 1, 1, 1, 1], [1, 1, 1, 1, 1]), ([-1, -2, -3, -4, -5], [-1, -3, -5, -2, -4])]", + "test_cases": { + "list": [ + "([1, 2, 3, 4, 5], [1, 3, 5, 2, 4])", + "([2, 1, 3, 5, 6, 4, 7], [2, 3, 6, 7, 1, 5, 4])", + "([], [])", + "([1], [1])", + "([1, 2], [1, 2])", + "([1, 2, 3], [1, 3, 2])", + "([1, 2, 3, 4], [1, 3, 2, 4])", + "([5, 4, 3, 2, 1], [5, 3, 1, 4, 2])", + "([10, 20, 30, 40, 50, 60], [10, 30, 50, 20, 40, 60])", + "([7, 6, 5, 4, 3, 2, 1], [7, 5, 3, 1, 6, 4, 2])", + "([100], [100])", + "([1, 3, 5, 7, 9], [1, 5, 9, 3, 7])", + "([2, 4, 6, 8], [2, 6, 4, 8])", + "([9, 8, 7, 6, 5, 4, 3, 2, 1], [9, 7, 5, 3, 1, 8, 6, 4, 2])", + "([1, 1, 1, 1, 1], [1, 1, 1, 1, 1])", + "([-1, -2, -3, -4, -5], [-1, -3, -5, -2, -4])" + ] + }, "body": " result = run_odd_even_list(Solution, head_list)\n assert_odd_even_list(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/pacific_atlantic_water_flow.json b/leetcode_py/cli/resources/leetcode/json/problems/pacific_atlantic_water_flow.json index e43798e..2fde306 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/pacific_atlantic_water_flow.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/pacific_atlantic_water_flow.json @@ -5,10 +5,10 @@ "problem_title": "Pacific Atlantic Water Flow", "difficulty": "Medium", "topics": "Array, Depth-First Search, Breadth-First Search, Matrix", - "_tags": { "list": ["grind"] }, - + "_tags": { + "list": ["grind"] + }, "readme_description": "There is an `m x n` rectangular island that borders both the **Pacific Ocean** and **Atlantic Ocean**. The **Pacific Ocean** touches the island's left and top edges, and the **Atlantic Ocean** touches the island's right and bottom edges.\n\nThe island is partitioned into a grid of square cells. You are given an `m x n` integer matrix `heights` where `heights[r][c]` represents the **height above sea level** of the cell at coordinate `(r, c)`.\n\nThe island receives a lot of rain, and the rain water can flow to neighboring cells directly north, south, east, and west if the neighboring cell's height is **less than or equal to** the current cell's height. Water can flow from any cell adjacent to an ocean into the ocean.\n\nReturn *a **2D list** of grid coordinates* `result` *where* `result[i] = [ri, ci]` *denotes that rain water can flow from cell* `(ri, ci)` *to **both** the Pacific and Atlantic oceans*.", - "_readme_examples": { "list": [ { @@ -19,10 +19,8 @@ } ] }, - "readme_constraints": "- `m == heights.length`\n- `n == heights[r].length`\n- `1 <= m, n <= 200`\n- `0 <= heights[r][c] <= 10^5`", "readme_additional": "", - "helpers_imports": "", "helpers_content": "", "helpers_run_name": "pacific_atlantic", @@ -31,16 +29,13 @@ "helpers_assert_name": "pacific_atlantic", "helpers_assert_signature": "(result: list[list[int]], expected: list[list[int]]) -> bool", "helpers_assert_body": " assert sorted(result) == sorted(expected)\n return True", - "solution_imports": "", "solution_contents": "", "solution_class_content": "", - "test_imports": "import pytest\nfrom leetcode_py import logged_test\nfrom .helpers import assert_pacific_atlantic, run_pacific_atlantic\nfrom .solution import Solution", "test_content": "", "test_class_name": "PacificAtlanticWaterFlow", "test_class_content": " def setup_method(self):\n self.solution = Solution()", - "_solution_methods": { "list": [ { @@ -50,23 +45,41 @@ } ] }, - "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, - "_test_methods": { "list": [ { "name": "test_pacific_atlantic", "signature": "(self, heights: list[list[int]], expected: list[list[int]])", "parametrize": "heights, expected", - "test_cases": "[([[1,2,2,3,5],[3,2,3,4,4],[2,4,5,3,1],[6,7,1,4,5],[5,1,1,2,4]], [[0,4],[1,3],[1,4],[2,2],[3,0],[3,1],[4,0]]), ([[1]], [[0,0]]), ([[2,1],[1,2]], [[0,0],[0,1],[1,0],[1,1]]), ([[1,2,3],[8,9,4],[7,6,5]], [[0,2],[1,0],[1,1],[1,2],[2,0],[2,1],[2,2]]), ([[3,3,3],[3,1,3],[0,2,4]], [[0,0],[0,1],[0,2],[1,0],[1,2],[2,0],[2,1],[2,2]]), ([[1,1],[1,1],[1,1]], [[0,0],[0,1],[1,0],[1,1],[2,0],[2,1]]), ([[10,10,10],[10,1,10],[10,10,10]], [[0,0],[0,1],[0,2],[1,0],[1,2],[2,0],[2,1],[2,2]]), ([[1,2,3,4],[12,13,14,5],[11,16,15,6],[10,9,8,7]], [[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]]), ([[5,4,3],[4,3,2],[3,2,1]], [[0,0],[0,1],[0,2],[1,0],[2,0]]), ([[1,3,2,4],[6,8,7,3],[5,7,6,2],[4,4,5,1]], [[0,3],[1,0],[1,1],[1,2],[2,0],[2,1],[2,2],[3,0],[3,1],[3,2]]), ([[4,2,7,3,4],[2,1,1,3,2],[1,1,2,2,1],[2,1,2,2,1],[2,1,1,1,1]], [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]]), ([[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]], [[0,0],[0,1],[0,2],[0,3],[0,4],[0,5],[0,6],[0,7],[0,8],[0,9],[0,10],[0,11],[0,12],[0,13],[0,14],[0,15],[0,16],[0,17],[0,18],[0,19],[1,0],[1,1],[1,2],[1,3],[1,4],[1,5],[1,6],[1,7],[1,8],[1,9],[1,10],[1,11],[1,12],[1,13],[1,14],[1,15],[1,16],[1,17],[1,18],[1,19]])]", + "test_cases": { + "list": [ + "([[1,2,2,3,5],[3,2,3,4,4],[2,4,5,3,1],[6,7,1,4,5],[5,1,1,2,4]], [[0,4],[1,3],[1,4],[2,2],[3,0],[3,1],[4,0]])", + "([[1]], [[0,0]])", + "([[2,1],[1,2]], [[0,0],[0,1],[1,0],[1,1]])", + "([[1,2,3],[8,9,4],[7,6,5]], [[0,2],[1,0],[1,1],[1,2],[2,0],[2,1],[2,2]])", + "([[3,3,3],[3,1,3],[0,2,4]], [[0,0],[0,1],[0,2],[1,0],[1,2],[2,0],[2,1],[2,2]])", + "([[1,1],[1,1],[1,1]], [[0,0],[0,1],[1,0],[1,1],[2,0],[2,1]])", + "([[10,10,10],[10,1,10],[10,10,10]], [[0,0],[0,1],[0,2],[1,0],[1,2],[2,0],[2,1],[2,2]])", + "([[1,2,3,4],[12,13,14,5],[11,16,15,6],[10,9,8,7]], [[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]])", + "([[5,4,3],[4,3,2],[3,2,1]], [[0,0],[0,1],[0,2],[1,0],[2,0]])", + "([[1,3,2,4],[6,8,7,3],[5,7,6,2],[4,4,5,1]], [[0,3],[1,0],[1,1],[1,2],[2,0],[2,1],[2,2],[3,0],[3,1],[3,2]])", + "([[4,2,7,3,4],[2,1,1,3,2],[1,1,2,2,1],[2,1,2,2,1],[2,1,1,1,1]], [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]])", + "([[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]], [[0,0],[0,1],[0,2],[0,3],[0,4],[0,5],[0,6],[0,7],[0,8],[0,9],[0,10],[0,11],[0,12],[0,13],[0,14],[0,15],[0,16],[0,17],[0,18],[0,19],[1,0],[1,1],[1,2],[1,3],[1,4],[1,5],[1,6],[1,7],[1,8],[1,9],[1,10],[1,11],[1,12],[1,13],[1,14],[1,15],[1,16],[1,17],[1,18],[1,19]])" + ] + }, "body": " result = run_pacific_atlantic(Solution, heights)\n assert_pacific_atlantic(result, expected)" } ] }, - "playground_imports": "from helpers import run_pacific_atlantic, assert_pacific_atlantic\nfrom solution import Solution", "playground_setup": "# Example test case\nheights = [[1,2,2,3,5],[3,2,3,4,4],[2,4,5,3,1],[6,7,1,4,5],[5,1,1,2,4]]\nexpected = [[0,4],[1,3],[1,4],[2,2],[3,0],[3,1],[4,0]]", "playground_run": "result = run_pacific_atlantic(Solution, heights)\nresult", diff --git a/leetcode_py/cli/resources/leetcode/json/problems/partition_equal_subset_sum.json b/leetcode_py/cli/resources/leetcode/json/problems/partition_equal_subset_sum.json index dd0becc..19b8655 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/partition_equal_subset_sum.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/partition_equal_subset_sum.json @@ -5,7 +5,9 @@ "problem_title": "Partition Equal Subset Sum", "difficulty": "Medium", "topics": "Array, Dynamic Programming", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "Given an integer array `nums`, return `true` if you can partition the array into two subsets such that the sum of the elements in both subsets is equal or `false` otherwise.", "_readme_examples": { "list": [ @@ -44,7 +46,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -52,7 +60,25 @@ "name": "test_can_partition", "signature": "(self, nums: list[int], expected: bool)", "parametrize": "nums, expected", - "test_cases": "[([1, 5, 11, 5], True), ([1, 2, 3, 5], False), ([1, 1], True), ([1], False), ([2, 2, 1, 1], True), ([100], False), ([1, 2, 5], False), ([1, 3, 5, 7], True), ([2, 2, 3, 5], False), ([1, 2, 3, 4, 5, 6, 7], True), ([3, 3, 3, 4, 5], True), ([1, 1, 1, 1], True), ([23, 13, 11, 7, 6, 5, 5], True), ([1, 5, 3], False), ([4, 4, 4, 4, 4, 4], True)]", + "test_cases": { + "list": [ + "([1, 5, 11, 5], True)", + "([1, 2, 3, 5], False)", + "([1, 1], True)", + "([1], False)", + "([2, 2, 1, 1], True)", + "([100], False)", + "([1, 2, 5], False)", + "([1, 3, 5, 7], True)", + "([2, 2, 3, 5], False)", + "([1, 2, 3, 4, 5, 6, 7], True)", + "([3, 3, 3, 4, 5], True)", + "([1, 1, 1, 1], True)", + "([23, 13, 11, 7, 6, 5, 5], True)", + "([1, 5, 3], False)", + "([4, 4, 4, 4, 4, 4], True)" + ] + }, "body": " result = run_can_partition(Solution, nums)\n assert_can_partition(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/path_sum_ii.json b/leetcode_py/cli/resources/leetcode/json/problems/path_sum_ii.json index 0923ddc..21eee96 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/path_sum_ii.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/path_sum_ii.json @@ -5,8 +5,9 @@ "problem_title": "Path Sum II", "difficulty": "Medium", "topics": "Backtracking, Tree, Depth-First Search, Binary Tree", - "_tags": { "list": ["grind"] }, - + "_tags": { + "list": ["grind"] + }, "readme_description": "Given the `root` of a binary tree and an integer `targetSum`, return all **root-to-leaf** paths where the sum of the node values in the path equals `targetSum`. Each path should be returned as a list of the node **values**, not node references.\n\nA **root-to-leaf** path is a path starting from the root and ending at any leaf node. A **leaf** is a node with no children.", "_readme_examples": { "list": [ @@ -16,12 +17,13 @@ { "content": "![Example 2](https://assets.leetcode.com/uploads/2021/01/18/pathsum2.jpg)\n\n```\nInput: root = [1,2,3], targetSum = 5\nOutput: []\n```" }, - { "content": "```\nInput: root = [1,2], targetSum = 0\nOutput: []\n```" } + { + "content": "```\nInput: root = [1,2], targetSum = 0\nOutput: []\n```" + } ] }, "readme_constraints": "- The number of nodes in the tree is in the range `[0, 5000]`.\n- `-1000 <= Node.val <= 1000`\n- `-1000 <= targetSum <= 1000`", "readme_additional": "", - "helpers_imports": "from leetcode_py import TreeNode", "helpers_content": "", "helpers_run_name": "path_sum", @@ -30,16 +32,13 @@ "helpers_assert_name": "path_sum", "helpers_assert_signature": "(result: list[list[int]], expected: list[list[int]]) -> bool", "helpers_assert_body": " # Sort both result and expected for comparison since order may vary\n result_sorted = sorted([sorted(path) for path in result])\n expected_sorted = sorted([sorted(path) for path in expected])\n assert result_sorted == expected_sorted\n return True", - "solution_imports": "from leetcode_py import TreeNode", "solution_contents": "", "solution_class_content": "", - "test_imports": "import pytest\nfrom leetcode_py import logged_test\nfrom .helpers import assert_path_sum, run_path_sum\nfrom .solution import Solution", "test_content": "", "test_class_name": "PathSumII", "test_class_content": " def setup_method(self):\n self.solution = Solution()", - "_solution_methods": { "list": [ { @@ -49,23 +48,41 @@ } ] }, - "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, - "_test_methods": { "list": [ { "name": "test_path_sum", "signature": "(self, root_list: list[int | None], target_sum: int, expected: list[list[int]])", "parametrize": "root_list, target_sum, expected", - "test_cases": "[([5, 4, 8, 11, None, 13, 4, 7, 2, None, None, 5, 1], 22, [[5, 4, 11, 2], [5, 8, 4, 5]]), ([1, 2, 3], 5, []), ([1, 2], 0, []), ([], 0, []), ([1], 1, [[1]]), ([1], 0, []), ([1, 2, 3], 4, [[1, 3]]), ([5, 4, 8, 11, None, 13, 4, 7, 2, None, None, None, 1], 22, [[5, 4, 11, 2]]), ([1, -2, -3, 1, 3, -2, None, -1], -1, [[1, -2, 1, -1]]), ([1, 2, 3, 4, 5], 7, [[1, 2, 4]]), ([2, 1, 3], 3, [[2, 1]]), ([1, 2, 3, 4, 5, 6, 7], 8, [[1, 2, 5]])]", + "test_cases": { + "list": [ + "([5, 4, 8, 11, None, 13, 4, 7, 2, None, None, 5, 1], 22, [[5, 4, 11, 2], [5, 8, 4, 5]])", + "([1, 2, 3], 5, [])", + "([1, 2], 0, [])", + "([], 0, [])", + "([1], 1, [[1]])", + "([1], 0, [])", + "([1, 2, 3], 4, [[1, 3]])", + "([5, 4, 8, 11, None, 13, 4, 7, 2, None, None, None, 1], 22, [[5, 4, 11, 2]])", + "([1, -2, -3, 1, 3, -2, None, -1], -1, [[1, -2, 1, -1]])", + "([1, 2, 3, 4, 5], 7, [[1, 2, 4]])", + "([2, 1, 3], 3, [[2, 1]])", + "([1, 2, 3, 4, 5, 6, 7], 8, [[1, 2, 5]])" + ] + }, "body": " result = run_path_sum(Solution, root_list, target_sum)\n assert_path_sum(result, expected)" } ] }, - "playground_imports": "from helpers import run_path_sum, assert_path_sum\nfrom solution import Solution\nfrom leetcode_py import TreeNode", "playground_setup": "# Example test case\nroot_list = [5, 4, 8, 11, None, 13, 4, 7, 2, None, None, 5, 1]\ntarget_sum = 22\nexpected = [[5, 4, 11, 2], [5, 8, 4, 5]]", "playground_run": "result = run_path_sum(Solution, root_list, target_sum)\nresult", diff --git a/leetcode_py/cli/resources/leetcode/json/problems/permutations.json b/leetcode_py/cli/resources/leetcode/json/problems/permutations.json index 10960fe..477183f 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/permutations.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/permutations.json @@ -5,15 +5,21 @@ "problem_title": "Permutations", "difficulty": "Medium", "topics": "Array, Backtracking", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "Given an array `nums` of distinct integers, return all the possible permutations. You can return the answer in any order.", "_readme_examples": { "list": [ { "content": "```\nInput: nums = [1,2,3]\nOutput: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]\n```" }, - { "content": "```\nInput: nums = [0,1]\nOutput: [[0,1],[1,0]]\n```" }, - { "content": "```\nInput: nums = [1]\nOutput: [[1]]\n```" } + { + "content": "```\nInput: nums = [0,1]\nOutput: [[0,1],[1,0]]\n```" + }, + { + "content": "```\nInput: nums = [1]\nOutput: [[1]]\n```" + } ] }, "readme_constraints": "- 1 <= nums.length <= 6\n- -10 <= nums[i] <= 10\n- All the integers of nums are unique.", @@ -43,7 +49,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -51,7 +63,22 @@ "name": "test_permute", "signature": "(self, nums: list[int], expected: list[list[int]])", "parametrize": "nums, expected", - "test_cases": "[([1, 2, 3], [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]), ([0, 1], [[0, 1], [1, 0]]), ([1], [[1]]), ([2, 1], [[2, 1], [1, 2]]), ([0], [[0]]), ([-1, 0], [[-1, 0], [0, -1]]), ([1, 2], [[1, 2], [2, 1]]), ([3, 2, 1], [[3, 2, 1], [3, 1, 2], [2, 3, 1], [2, 1, 3], [1, 3, 2], [1, 2, 3]]), ([-1, 1], [[-1, 1], [1, -1]]), ([5, 4, 3, 2], [[5, 4, 3, 2], [5, 4, 2, 3], [5, 3, 4, 2], [5, 3, 2, 4], [5, 2, 4, 3], [5, 2, 3, 4], [4, 5, 3, 2], [4, 5, 2, 3], [4, 3, 5, 2], [4, 3, 2, 5], [4, 2, 5, 3], [4, 2, 3, 5], [3, 5, 4, 2], [3, 5, 2, 4], [3, 4, 5, 2], [3, 4, 2, 5], [3, 2, 5, 4], [3, 2, 4, 5], [2, 5, 4, 3], [2, 5, 3, 4], [2, 4, 5, 3], [2, 4, 3, 5], [2, 3, 5, 4], [2, 3, 4, 5]]), ([0, -1, 1], [[0, -1, 1], [0, 1, -1], [-1, 0, 1], [-1, 1, 0], [1, 0, -1], [1, -1, 0]]), ([10, -10], [[10, -10], [-10, 10]])]", + "test_cases": { + "list": [ + "([1, 2, 3], [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]])", + "([0, 1], [[0, 1], [1, 0]])", + "([1], [[1]])", + "([2, 1], [[2, 1], [1, 2]])", + "([0], [[0]])", + "([-1, 0], [[-1, 0], [0, -1]])", + "([1, 2], [[1, 2], [2, 1]])", + "([3, 2, 1], [[3, 2, 1], [3, 1, 2], [2, 3, 1], [2, 1, 3], [1, 3, 2], [1, 2, 3]])", + "([-1, 1], [[-1, 1], [1, -1]])", + "([5, 4, 3, 2], [[5, 4, 3, 2], [5, 4, 2, 3], [5, 3, 4, 2], [5, 3, 2, 4], [5, 2, 4, 3], [5, 2, 3, 4], [4, 5, 3, 2], [4, 5, 2, 3], [4, 3, 5, 2], [4, 3, 2, 5], [4, 2, 5, 3], [4, 2, 3, 5], [3, 5, 4, 2], [3, 5, 2, 4], [3, 4, 5, 2], [3, 4, 2, 5], [3, 2, 5, 4], [3, 2, 4, 5], [2, 5, 4, 3], [2, 5, 3, 4], [2, 4, 5, 3], [2, 4, 3, 5], [2, 3, 5, 4], [2, 3, 4, 5]])", + "([0, -1, 1], [[0, -1, 1], [0, 1, -1], [-1, 0, 1], [-1, 1, 0], [1, 0, -1], [1, -1, 0]])", + "([10, -10], [[10, -10], [-10, 10]])" + ] + }, "body": " result = run_permute(Solution, nums)\n assert_permute(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/product_of_array_except_self.json b/leetcode_py/cli/resources/leetcode/json/problems/product_of_array_except_self.json index 7497565..667a1d3 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/product_of_array_except_self.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/product_of_array_except_self.json @@ -5,12 +5,18 @@ "problem_title": "Product of Array Except Self", "difficulty": "Medium", "topics": "Array, Prefix Sum", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "Given an integer array `nums`, return an array `answer` such that `answer[i]` is equal to the product of all the elements of `nums` except `nums[i]`.\n\nThe product of any prefix or suffix of `nums` is guaranteed to fit in a 32-bit integer.\n\nYou must write an algorithm that runs in O(n) time and without using the division operation.", "_readme_examples": { "list": [ - { "content": "```\nInput: nums = [1,2,3,4]\nOutput: [24,12,8,6]\n```" }, - { "content": "```\nInput: nums = [-1,1,0,-3,3]\nOutput: [0,0,9,0,0]\n```" } + { + "content": "```\nInput: nums = [1,2,3,4]\nOutput: [24,12,8,6]\n```" + }, + { + "content": "```\nInput: nums = [-1,1,0,-3,3]\nOutput: [0,0,9,0,0]\n```" + } ] }, "readme_constraints": "- 2 <= nums.length <= 10^5\n- -30 <= nums[i] <= 30\n- The input is generated such that answer[i] is guaranteed to fit in a 32-bit integer.", @@ -40,7 +46,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -48,7 +60,25 @@ "name": "test_product_except_self", "signature": "(self, nums: list[int], expected: list[int])", "parametrize": "nums, expected", - "test_cases": "[([1, 2, 3, 4], [24, 12, 8, 6]), ([-1, 1, 0, -3, 3], [0, 0, 9, 0, 0]), ([2, 3, 4, 5], [60, 40, 30, 24]), ([1, 1], [1, 1]), ([5, 2], [2, 5]), ([0, 1, 2, 3], [6, 0, 0, 0]), ([1, 0, 3, 4], [0, 12, 0, 0]), ([-1, -2, -3], [6, 3, 2]), ([2, 2, 2], [4, 4, 4]), ([10, 3, 5, 6, 2], [180, 600, 360, 300, 900]), ([0, 0], [0, 0]), ([1, 2, 0, 4], [0, 0, 8, 0]), ([-2, 0, -3, 4], [0, 24, 0, 0]), ([7, 1, 3], [3, 21, 7]), ([4, 5, 1, 8, 2], [80, 64, 320, 40, 160])]", + "test_cases": { + "list": [ + "([1, 2, 3, 4], [24, 12, 8, 6])", + "([-1, 1, 0, -3, 3], [0, 0, 9, 0, 0])", + "([2, 3, 4, 5], [60, 40, 30, 24])", + "([1, 1], [1, 1])", + "([5, 2], [2, 5])", + "([0, 1, 2, 3], [6, 0, 0, 0])", + "([1, 0, 3, 4], [0, 12, 0, 0])", + "([-1, -2, -3], [6, 3, 2])", + "([2, 2, 2], [4, 4, 4])", + "([10, 3, 5, 6, 2], [180, 600, 360, 300, 900])", + "([0, 0], [0, 0])", + "([1, 2, 0, 4], [0, 0, 8, 0])", + "([-2, 0, -3, 4], [0, 24, 0, 0])", + "([7, 1, 3], [3, 21, 7])", + "([4, 5, 1, 8, 2], [80, 64, 320, 40, 160])" + ] + }, "body": " result = run_product_except_self(Solution, nums)\n assert_product_except_self(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/ransom_note.json b/leetcode_py/cli/resources/leetcode/json/problems/ransom_note.json index 9425e00..16c68ed 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/ransom_note.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/ransom_note.json @@ -5,13 +5,21 @@ "problem_title": "Ransom Note", "difficulty": "Easy", "topics": "Hash Table, String, Counting", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "Given two strings `ransomNote` and `magazine`, return `true` if `ransomNote` can be constructed by using the letters from `magazine` and `false` otherwise.\n\nEach letter in `magazine` can only be used once in `ransomNote`.", "_readme_examples": { "list": [ - { "content": "```\nInput: ransomNote = \"a\", magazine = \"b\"\nOutput: false\n```" }, - { "content": "```\nInput: ransomNote = \"aa\", magazine = \"ab\"\nOutput: false\n```" }, - { "content": "```\nInput: ransomNote = \"aa\", magazine = \"aab\"\nOutput: true\n```" } + { + "content": "```\nInput: ransomNote = \"a\", magazine = \"b\"\nOutput: false\n```" + }, + { + "content": "```\nInput: ransomNote = \"aa\", magazine = \"ab\"\nOutput: false\n```" + }, + { + "content": "```\nInput: ransomNote = \"aa\", magazine = \"aab\"\nOutput: true\n```" + } ] }, "readme_constraints": "- 1 <= ransomNote.length, magazine.length <= 10^5\n- ransomNote and magazine consist of lowercase English letters.", @@ -41,7 +49,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -49,7 +63,21 @@ "name": "test_can_construct", "signature": "(self, ransom_note: str, magazine: str, expected: bool)", "parametrize": "ransom_note, magazine, expected", - "test_cases": "[('a', 'b', False), ('aa', 'ab', False), ('aa', 'aab', True), ('aab', 'baa', True), ('', '', True), ('', 'abc', True), ('abc', '', False), ('abc', 'abc', True), ('abc', 'cba', True), ('aaa', 'aa', False), ('ab', 'ba', True)]", + "test_cases": { + "list": [ + "('a', 'b', False)", + "('aa', 'ab', False)", + "('aa', 'aab', True)", + "('aab', 'baa', True)", + "('', '', True)", + "('', 'abc', True)", + "('abc', '', False)", + "('abc', 'abc', True)", + "('abc', 'cba', True)", + "('aaa', 'aa', False)", + "('ab', 'ba', True)" + ] + }, "body": " result = run_can_construct(Solution, ransom_note, magazine)\n assert_can_construct(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/remove_nth_node_from_end_of_list.json b/leetcode_py/cli/resources/leetcode/json/problems/remove_nth_node_from_end_of_list.json index f2e0e8b..f7ea4c4 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/remove_nth_node_from_end_of_list.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/remove_nth_node_from_end_of_list.json @@ -5,15 +5,21 @@ "problem_title": "Remove Nth Node From End of List", "difficulty": "Medium", "topics": "Linked List, Two Pointers", - "_tags": { "list": ["grind"] }, + "_tags": { + "list": ["grind"] + }, "readme_description": "Given the `head` of a linked list, remove the `nth` node from the end of the list and return its head.", "_readme_examples": { "list": [ { "content": "![Example 1](https://assets.leetcode.com/uploads/2020/10/03/remove_ex1.jpg)\n\n```\nInput: head = [1,2,3,4,5], n = 2\nOutput: [1,2,3,5]\n```" }, - { "content": "```\nInput: head = [1], n = 1\nOutput: []\n```" }, - { "content": "```\nInput: head = [1,2], n = 1\nOutput: [1]\n```" } + { + "content": "```\nInput: head = [1], n = 1\nOutput: []\n```" + }, + { + "content": "```\nInput: head = [1,2], n = 1\nOutput: [1]\n```" + } ] }, "readme_constraints": "- The number of nodes in the list is `sz`.\n- `1 <= sz <= 30`\n- `0 <= Node.val <= 100`\n- `1 <= n <= sz`", @@ -43,7 +49,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -51,7 +63,28 @@ "name": "test_remove_nth_from_end", "signature": "(self, head_list: list[int], n: int, expected: list[int])", "parametrize": "head_list, n, expected", - "test_cases": "[([1, 2, 3, 4, 5], 2, [1, 2, 3, 5]), ([1], 1, []), ([1, 2], 1, [1]), ([1, 2], 2, [2]), ([1, 2, 3], 3, [2, 3]), ([1, 2, 3], 1, [1, 2]), ([1, 2, 3, 4], 2, [1, 2, 4]), ([1, 2, 3, 4], 4, [2, 3, 4]), ([5], 1, []), ([10, 20], 1, [10]), ([10, 20], 2, [20]), ([1, 2, 3, 4, 5, 6], 3, [1, 2, 3, 5, 6]), ([7, 8, 9, 10], 1, [7, 8, 9]), ([100], 1, []), ([1, 2, 3, 4, 5, 6, 7], 4, [1, 2, 3, 5, 6, 7]), ([0, 1, 2], 2, [0, 2]), ([50, 60, 70, 80, 90], 5, [60, 70, 80, 90]), ([25, 35], 1, [25])]", + "test_cases": { + "list": [ + "([1, 2, 3, 4, 5], 2, [1, 2, 3, 5])", + "([1], 1, [])", + "([1, 2], 1, [1])", + "([1, 2], 2, [2])", + "([1, 2, 3], 3, [2, 3])", + "([1, 2, 3], 1, [1, 2])", + "([1, 2, 3, 4], 2, [1, 2, 4])", + "([1, 2, 3, 4], 4, [2, 3, 4])", + "([5], 1, [])", + "([10, 20], 1, [10])", + "([10, 20], 2, [20])", + "([1, 2, 3, 4, 5, 6], 3, [1, 2, 3, 5, 6])", + "([7, 8, 9, 10], 1, [7, 8, 9])", + "([100], 1, [])", + "([1, 2, 3, 4, 5, 6, 7], 4, [1, 2, 3, 5, 6, 7])", + "([0, 1, 2], 2, [0, 2])", + "([50, 60, 70, 80, 90], 5, [60, 70, 80, 90])", + "([25, 35], 1, [25])" + ] + }, "body": " result = run_remove_nth_from_end(Solution, head_list, n)\n assert_remove_nth_from_end(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/reverse_linked_list.json b/leetcode_py/cli/resources/leetcode/json/problems/reverse_linked_list.json index 5c01cfb..f59f8bf 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/reverse_linked_list.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/reverse_linked_list.json @@ -5,7 +5,9 @@ "problem_title": "Reverse Linked List", "difficulty": "Easy", "topics": "Linked List, Recursion", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "Given the `head` of a singly linked list, reverse the list, and return the reversed list.", "_readme_examples": { "list": [ @@ -15,7 +17,9 @@ { "content": "![Example 2](https://assets.leetcode.com/uploads/2021/02/19/rev1ex2.jpg)\n\n```\nInput: head = [1,2]\nOutput: [2,1]\n```" }, - { "content": "```\nInput: head = []\nOutput: []\n```" } + { + "content": "```\nInput: head = []\nOutput: []\n```" + } ] }, "readme_constraints": "- The number of nodes in the list is the range `[0, 5000]`.\n- `-5000 <= Node.val <= 5000`", @@ -45,7 +49,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -53,7 +63,25 @@ "name": "test_reverse_list", "signature": "(self, head_list: list[int], expected_list: list[int])", "parametrize": "head_list, expected_list", - "test_cases": "[([1, 2, 3, 4, 5], [5, 4, 3, 2, 1]), ([1, 2], [2, 1]), ([1], [1]), ([], []), ([1, 2, 3], [3, 2, 1]), ([1, 2, 3, 4], [4, 3, 2, 1]), ([-1, -2, -3], [-3, -2, -1]), ([0], [0]), ([5000, -5000], [-5000, 5000]), ([1, 1, 1], [1, 1, 1]), ([10, 20, 30, 40, 50, 60], [60, 50, 40, 30, 20, 10]), ([-100, 0, 100], [100, 0, -100]), ([7], [7]), ([1, 2, 3, 4, 5, 6, 7], [7, 6, 5, 4, 3, 2, 1]), ([42, 42, 42, 42], [42, 42, 42, 42])]", + "test_cases": { + "list": [ + "([1, 2, 3, 4, 5], [5, 4, 3, 2, 1])", + "([1, 2], [2, 1])", + "([1], [1])", + "([], [])", + "([1, 2, 3], [3, 2, 1])", + "([1, 2, 3, 4], [4, 3, 2, 1])", + "([-1, -2, -3], [-3, -2, -1])", + "([0], [0])", + "([5000, -5000], [-5000, 5000])", + "([1, 1, 1], [1, 1, 1])", + "([10, 20, 30, 40, 50, 60], [60, 50, 40, 30, 20, 10])", + "([-100, 0, 100], [100, 0, -100])", + "([7], [7])", + "([1, 2, 3, 4, 5, 6, 7], [7, 6, 5, 4, 3, 2, 1])", + "([42, 42, 42, 42], [42, 42, 42, 42])" + ] + }, "body": " result = run_reverse_list(Solution, head_list)\n assert_reverse_list(result, expected_list)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/reverse_linked_list_ii.json b/leetcode_py/cli/resources/leetcode/json/problems/reverse_linked_list_ii.json index 0fd9061..9c6d7b0 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/reverse_linked_list_ii.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/reverse_linked_list_ii.json @@ -5,14 +5,18 @@ "problem_title": "Reverse Linked List II", "difficulty": "Medium", "topics": "Linked List", - "_tags": { "list": [] }, + "_tags": { + "list": [] + }, "readme_description": "Given the `head` of a singly linked list and two integers `left` and `right` where `left <= right`, reverse the nodes of the list from position `left` to position `right`, and return the reversed list.", "_readme_examples": { "list": [ { "content": "```\nInput: head = [1,2,3,4,5], left = 2, right = 4\nOutput: [1,4,3,2,5]\n```" }, - { "content": "```\nInput: head = [5], left = 1, right = 1\nOutput: [5]\n```" } + { + "content": "```\nInput: head = [5], left = 1, right = 1\nOutput: [5]\n```" + } ] }, "readme_constraints": "- The number of nodes in the list is n\n- 1 <= n <= 500\n- -500 <= Node.val <= 500\n- 1 <= left <= right <= n", @@ -42,7 +46,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -50,7 +60,22 @@ "name": "test_reverse_between", "signature": "(self, head_list: list[int], left: int, right: int, expected_list: list[int])", "parametrize": "head_list, left, right, expected_list", - "test_cases": "[([1, 2, 3, 4, 5], 2, 4, [1, 4, 3, 2, 5]), ([5], 1, 1, [5]), ([1, 2], 1, 2, [2, 1]), ([1, 2, 3], 1, 3, [3, 2, 1]), ([1, 2, 3, 4, 5], 1, 5, [5, 4, 3, 2, 1]), ([1, 2, 3, 4, 5], 3, 3, [1, 2, 3, 4, 5]), ([1, 2, 3, 4], 2, 3, [1, 3, 2, 4]), ([1, 2, 3, 4, 5, 6], 3, 5, [1, 2, 5, 4, 3, 6]), ([10], 1, 1, [10]), ([1, 2, 3, 4, 5, 6, 7], 1, 7, [7, 6, 5, 4, 3, 2, 1]), ([3, 5], 1, 1, [3, 5]), ([7, 9, 2, 10, 1, 8, 6], 4, 6, [7, 9, 2, 8, 1, 10, 6])]", + "test_cases": { + "list": [ + "([1, 2, 3, 4, 5], 2, 4, [1, 4, 3, 2, 5])", + "([5], 1, 1, [5])", + "([1, 2], 1, 2, [2, 1])", + "([1, 2, 3], 1, 3, [3, 2, 1])", + "([1, 2, 3, 4, 5], 1, 5, [5, 4, 3, 2, 1])", + "([1, 2, 3, 4, 5], 3, 3, [1, 2, 3, 4, 5])", + "([1, 2, 3, 4], 2, 3, [1, 3, 2, 4])", + "([1, 2, 3, 4, 5, 6], 3, 5, [1, 2, 5, 4, 3, 6])", + "([10], 1, 1, [10])", + "([1, 2, 3, 4, 5, 6, 7], 1, 7, [7, 6, 5, 4, 3, 2, 1])", + "([3, 5], 1, 1, [3, 5])", + "([7, 9, 2, 10, 1, 8, 6], 4, 6, [7, 9, 2, 8, 1, 10, 6])" + ] + }, "body": " result = run_reverse_between(Solution, head_list, left, right)\n assert_reverse_between(result, expected_list)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/rotate_array.json b/leetcode_py/cli/resources/leetcode/json/problems/rotate_array.json index 3a11db5..f2cb129 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/rotate_array.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/rotate_array.json @@ -5,7 +5,9 @@ "problem_title": "Rotate Array", "difficulty": "Medium", "topics": "Array, Math, Two Pointers", - "_tags": { "list": ["grind"] }, + "_tags": { + "list": ["grind"] + }, "readme_description": "Given an integer array `nums`, rotate the array to the right by `k` steps, where `k` is non-negative.", "_readme_examples": { "list": [ @@ -44,7 +46,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -52,7 +60,25 @@ "name": "test_rotate", "signature": "(self, nums: list[int], k: int, expected: list[int])", "parametrize": "nums, k, expected", - "test_cases": "[([1, 2, 3, 4, 5, 6, 7], 3, [5, 6, 7, 1, 2, 3, 4]), ([-1, -100, 3, 99], 2, [3, 99, -1, -100]), ([1, 2], 1, [2, 1]), ([1], 1, [1]), ([1, 2, 3], 0, [1, 2, 3]), ([1, 2, 3], 3, [1, 2, 3]), ([1, 2, 3], 4, [3, 1, 2]), ([1, 2, 3, 4, 5], 2, [4, 5, 1, 2, 3]), ([1, 2, 3, 4, 5, 6], 4, [3, 4, 5, 6, 1, 2]), ([-1, -2, -3, -4], 1, [-4, -1, -2, -3]), ([1, 2, 3, 4, 5, 6, 7, 8, 9], 5, [5, 6, 7, 8, 9, 1, 2, 3, 4]), ([10, 20, 30], 6, [10, 20, 30]), ([5, 4, 3, 2, 1], 10, [5, 4, 3, 2, 1]), ([1, 2, 3, 4, 5, 6, 7, 8], 3, [6, 7, 8, 1, 2, 3, 4, 5]), ([100], 0, [100])]", + "test_cases": { + "list": [ + "([1, 2, 3, 4, 5, 6, 7], 3, [5, 6, 7, 1, 2, 3, 4])", + "([-1, -100, 3, 99], 2, [3, 99, -1, -100])", + "([1, 2], 1, [2, 1])", + "([1], 1, [1])", + "([1, 2, 3], 0, [1, 2, 3])", + "([1, 2, 3], 3, [1, 2, 3])", + "([1, 2, 3], 4, [3, 1, 2])", + "([1, 2, 3, 4, 5], 2, [4, 5, 1, 2, 3])", + "([1, 2, 3, 4, 5, 6], 4, [3, 4, 5, 6, 1, 2])", + "([-1, -2, -3, -4], 1, [-4, -1, -2, -3])", + "([1, 2, 3, 4, 5, 6, 7, 8, 9], 5, [5, 6, 7, 8, 9, 1, 2, 3, 4])", + "([10, 20, 30], 6, [10, 20, 30])", + "([5, 4, 3, 2, 1], 10, [5, 4, 3, 2, 1])", + "([1, 2, 3, 4, 5, 6, 7, 8], 3, [6, 7, 8, 1, 2, 3, 4, 5])", + "([100], 0, [100])" + ] + }, "body": " result = run_rotate(Solution, nums, k)\n assert_rotate(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/rotate_image.json b/leetcode_py/cli/resources/leetcode/json/problems/rotate_image.json index edf9185..607f44a 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/rotate_image.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/rotate_image.json @@ -5,7 +5,9 @@ "problem_title": "Rotate Image", "difficulty": "Medium", "topics": "Array, Math, Matrix", - "_tags": { "list": ["blind-75"] }, + "_tags": { + "list": ["blind-75"] + }, "readme_description": "You are given an `n x n` 2D `matrix` representing an image, rotate the image by **90** degrees (clockwise).\n\nYou have to rotate the image **in-place**, which means you have to modify the input 2D matrix directly. **DO NOT** allocate another 2D matrix and do the rotation.", "_readme_examples": { "list": [ @@ -44,7 +46,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -52,7 +60,22 @@ "name": "test_rotate", "signature": "(self, matrix: list[list[int]], expected: list[list[int]])", "parametrize": "matrix, expected", - "test_cases": "[([[1,2,3],[4,5,6],[7,8,9]], [[7,4,1],[8,5,2],[9,6,3]]), ([[5,1,9,11],[2,4,8,10],[13,3,6,7],[15,14,12,16]], [[15,13,2,5],[14,3,4,1],[12,6,8,9],[16,7,10,11]]), ([[1]], [[1]]), ([[1,2],[3,4]], [[3,1],[4,2]]), ([[1,2,3,4,5],[6,7,8,9,10],[11,12,13,14,15],[16,17,18,19,20],[21,22,23,24,25]], [[21,16,11,6,1],[22,17,12,7,2],[23,18,13,8,3],[24,19,14,9,4],[25,20,15,10,5]]), ([[0,0,0],[0,0,0],[0,0,0]], [[0,0,0],[0,0,0],[0,0,0]]), ([[-1,-2,-3],[-4,-5,-6],[-7,-8,-9]], [[-7,-4,-1],[-8,-5,-2],[-9,-6,-3]]), ([[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]], [[13,9,5,1],[14,10,6,2],[15,11,7,3],[16,12,8,4]]), ([[100,200],[300,400]], [[300,100],[400,200]]), ([[1,2,3],[4,5,6],[7,8,9]], [[7,4,1],[8,5,2],[9,6,3]]), ([[10,20,30,40,50,60],[70,80,90,100,110,120],[130,140,150,160,170,180],[190,200,210,220,230,240],[250,260,270,280,290,300],[310,320,330,340,350,360]], [[310,250,190,130,70,10],[320,260,200,140,80,20],[330,270,210,150,90,30],[340,280,220,160,100,40],[350,290,230,170,110,50],[360,300,240,180,120,60]]), ([[-1000,1000],[-500,500]], [[-500,-1000],[500,1000]])]", + "test_cases": { + "list": [ + "([[1,2,3],[4,5,6],[7,8,9]], [[7,4,1],[8,5,2],[9,6,3]])", + "([[5,1,9,11],[2,4,8,10],[13,3,6,7],[15,14,12,16]], [[15,13,2,5],[14,3,4,1],[12,6,8,9],[16,7,10,11]])", + "([[1]], [[1]])", + "([[1,2],[3,4]], [[3,1],[4,2]])", + "([[1,2,3,4,5],[6,7,8,9,10],[11,12,13,14,15],[16,17,18,19,20],[21,22,23,24,25]], [[21,16,11,6,1],[22,17,12,7,2],[23,18,13,8,3],[24,19,14,9,4],[25,20,15,10,5]])", + "([[0,0,0],[0,0,0],[0,0,0]], [[0,0,0],[0,0,0],[0,0,0]])", + "([[-1,-2,-3],[-4,-5,-6],[-7,-8,-9]], [[-7,-4,-1],[-8,-5,-2],[-9,-6,-3]])", + "([[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]], [[13,9,5,1],[14,10,6,2],[15,11,7,3],[16,12,8,4]])", + "([[100,200],[300,400]], [[300,100],[400,200]])", + "([[1,2,3],[4,5,6],[7,8,9]], [[7,4,1],[8,5,2],[9,6,3]])", + "([[10,20,30,40,50,60],[70,80,90,100,110,120],[130,140,150,160,170,180],[190,200,210,220,230,240],[250,260,270,280,290,300],[310,320,330,340,350,360]], [[310,250,190,130,70,10],[320,260,200,140,80,20],[330,270,210,150,90,30],[340,280,220,160,100,40],[350,290,230,170,110,50],[360,300,240,180,120,60]])", + "([[-1000,1000],[-500,500]], [[-500,-1000],[500,1000]])" + ] + }, "body": " result = run_rotate(Solution, matrix)\n assert_rotate(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/rotting_oranges.json b/leetcode_py/cli/resources/leetcode/json/problems/rotting_oranges.json index f4eb7a5..cf14213 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/rotting_oranges.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/rotting_oranges.json @@ -5,7 +5,9 @@ "problem_title": "Rotting Oranges", "difficulty": "Medium", "topics": "Array, Breadth-First Search, Matrix", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "You are given an `m x n` `grid` where each cell can have one of three values:\n\n- `0` representing an empty cell,\n- `1` representing a fresh orange, or\n- `2` representing a rotten orange.\n\nEvery minute, any fresh orange that is **4-directionally adjacent** to a rotten orange becomes rotten.\n\nReturn *the minimum number of minutes that must elapse until no cell has a fresh orange*. If *this is impossible, return* `-1`.", "_readme_examples": { "list": [ @@ -47,7 +49,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -55,7 +63,21 @@ "name": "test_oranges_rotting", "signature": "(self, grid: list[list[int]], expected: int)", "parametrize": "grid, expected", - "test_cases": "[([[2, 1, 1], [1, 1, 0], [0, 1, 1]], 4), ([[2, 1, 1], [0, 1, 1], [1, 0, 1]], -1), ([[0, 2]], 0), ([[0]], 0), ([[1]], -1), ([[2]], 0), ([[1, 2]], 1), ([[2, 1]], 1), ([[0, 1, 2]], 1), ([[2, 2], [1, 1], [0, 0]], 1), ([[2, 1, 1], [1, 1, 1], [0, 1, 2]], 2)]", + "test_cases": { + "list": [ + "([[2, 1, 1], [1, 1, 0], [0, 1, 1]], 4)", + "([[2, 1, 1], [0, 1, 1], [1, 0, 1]], -1)", + "([[0, 2]], 0)", + "([[0]], 0)", + "([[1]], -1)", + "([[2]], 0)", + "([[1, 2]], 1)", + "([[2, 1]], 1)", + "([[0, 1, 2]], 1)", + "([[2, 2], [1, 1], [0, 0]], 1)", + "([[2, 1, 1], [1, 1, 1], [0, 1, 2]], 2)" + ] + }, "body": " result = run_oranges_rotting(Solution, grid)\n assert_oranges_rotting(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/same_tree.json b/leetcode_py/cli/resources/leetcode/json/problems/same_tree.json index 3fa5f8c..85c5604 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/same_tree.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/same_tree.json @@ -5,7 +5,9 @@ "problem_title": "Same Tree", "difficulty": "Easy", "topics": "Tree, Depth-First Search, Breadth-First Search, Binary Tree", - "_tags": { "list": ["blind-75"] }, + "_tags": { + "list": ["blind-75"] + }, "readme_description": "Given the roots of two binary trees `p` and `q`, write a function to check if they are the same or not.\n\nTwo binary trees are considered the same if they are structurally identical, and the nodes have the same value.", "_readme_examples": { "list": [ @@ -47,7 +49,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -55,7 +63,21 @@ "name": "test_is_same_tree", "signature": "(self, p_list: list[int | None], q_list: list[int | None], expected: bool)", "parametrize": "p_list, q_list, expected", - "test_cases": "[([1, 2, 3], [1, 2, 3], True), ([1, 2], [1, None, 2], False), ([1, 2, 1], [1, 1, 2], False), ([], [], True), ([1], [1], True), ([1], [2], False), ([1, None, 2], [1, 2], False), ([1, 2, 3, 4, 5], [1, 2, 3, 4, 5], True), ([1, 2, 3, 4, 5], [1, 2, 3, 4, 6], False), ([1, 2, 3, None, 4], [1, 2, 3, None, 4], True), ([1, 2, 3, None, 4], [1, 2, 3, 4, None], False)]", + "test_cases": { + "list": [ + "([1, 2, 3], [1, 2, 3], True)", + "([1, 2], [1, None, 2], False)", + "([1, 2, 1], [1, 1, 2], False)", + "([], [], True)", + "([1], [1], True)", + "([1], [2], False)", + "([1, None, 2], [1, 2], False)", + "([1, 2, 3, 4, 5], [1, 2, 3, 4, 5], True)", + "([1, 2, 3, 4, 5], [1, 2, 3, 4, 6], False)", + "([1, 2, 3, None, 4], [1, 2, 3, None, 4], True)", + "([1, 2, 3, None, 4], [1, 2, 3, 4, None], False)" + ] + }, "body": " result = run_is_same_tree(Solution, p_list, q_list)\n assert_is_same_tree(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/search_in_rotated_sorted_array.json b/leetcode_py/cli/resources/leetcode/json/problems/search_in_rotated_sorted_array.json index aae6977..d1aa94f 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/search_in_rotated_sorted_array.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/search_in_rotated_sorted_array.json @@ -5,13 +5,21 @@ "problem_title": "Search in Rotated Sorted Array", "difficulty": "Medium", "topics": "Array, Binary Search", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "There is an integer array `nums` sorted in ascending order (with **distinct** values).\n\nPrior to being passed to your function, `nums` is **possibly left rotated** at an unknown index `k` (`1 <= k < nums.length`) such that the resulting array is `[nums[k], nums[k+1], ..., nums[n-1], nums[0], nums[1], ..., nums[k-1]]` (**0-indexed**). For example, `[0,1,2,4,5,6,7]` might be left rotated by 3 indices and become `[4,5,6,7,0,1,2]`.\n\nGiven the array `nums` **after** the possible rotation and an integer `target`, return *the index of* `target` *if it is in* `nums`*, or* `-1` *if it is not in* `nums`.\n\nYou must write an algorithm with `O(log n)` runtime complexity.", "_readme_examples": { "list": [ - { "content": "```\nInput: nums = [4,5,6,7,0,1,2], target = 0\nOutput: 4\n```" }, - { "content": "```\nInput: nums = [4,5,6,7,0,1,2], target = 3\nOutput: -1\n```" }, - { "content": "```\nInput: nums = [1], target = 0\nOutput: -1\n```" } + { + "content": "```\nInput: nums = [4,5,6,7,0,1,2], target = 0\nOutput: 4\n```" + }, + { + "content": "```\nInput: nums = [4,5,6,7,0,1,2], target = 3\nOutput: -1\n```" + }, + { + "content": "```\nInput: nums = [1], target = 0\nOutput: -1\n```" + } ] }, "readme_constraints": "- `1 <= nums.length <= 5000`\n- `-10^4 <= nums[i] <= 10^4`\n- All values of `nums` are **unique**.\n- `nums` is an ascending array that is possibly rotated.\n- `-10^4 <= target <= 10^4`", @@ -41,7 +49,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -49,7 +63,25 @@ "name": "test_search", "signature": "(self, nums: list[int], target: int, expected: int)", "parametrize": "nums, target, expected", - "test_cases": "[([4, 5, 6, 7, 0, 1, 2], 0, 4), ([4, 5, 6, 7, 0, 1, 2], 3, -1), ([1], 0, -1), ([1], 1, 0), ([3, 1], 1, 1), ([1, 3], 3, 1), ([2, 1], 2, 0), ([5, 1, 3], 3, 2), ([4, 5, 6, 7, 8, 1, 2, 3], 8, 4), ([6, 7, 0, 1, 2, 3, 4, 5], 6, 0), ([7, 0, 1, 2, 3, 4, 5, 6], 7, 0), ([0, 1, 2, 3, 4, 5, 6, 7], 4, 4), ([3, 4, 5, 6, 7, 0, 1, 2], 2, 7), ([9, 0, 2, 7, 8], 3, -1), ([8, 9, 2, 3, 4], 9, 1)]", + "test_cases": { + "list": [ + "([4, 5, 6, 7, 0, 1, 2], 0, 4)", + "([4, 5, 6, 7, 0, 1, 2], 3, -1)", + "([1], 0, -1)", + "([1], 1, 0)", + "([3, 1], 1, 1)", + "([1, 3], 3, 1)", + "([2, 1], 2, 0)", + "([5, 1, 3], 3, 2)", + "([4, 5, 6, 7, 8, 1, 2, 3], 8, 4)", + "([6, 7, 0, 1, 2, 3, 4, 5], 6, 0)", + "([7, 0, 1, 2, 3, 4, 5, 6], 7, 0)", + "([0, 1, 2, 3, 4, 5, 6, 7], 4, 4)", + "([3, 4, 5, 6, 7, 0, 1, 2], 2, 7)", + "([9, 0, 2, 7, 8], 3, -1)", + "([8, 9, 2, 3, 4], 9, 1)" + ] + }, "body": " result = run_search(Solution, nums, target)\n assert_search(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/serialize_and_deserialize_binary_tree.json b/leetcode_py/cli/resources/leetcode/json/problems/serialize_and_deserialize_binary_tree.json index 4b4b99c..f0c12d3 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/serialize_and_deserialize_binary_tree.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/serialize_and_deserialize_binary_tree.json @@ -5,14 +5,18 @@ "problem_title": "Serialize and Deserialize Binary Tree", "difficulty": "Hard", "topics": "String, Tree, Depth-First Search, Breadth-First Search, Design, Binary Tree", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be reconstructed later in the same or another computer environment.\n\nDesign an algorithm to serialize and deserialize a binary tree. There is no restriction on how your serialization/deserialization algorithm should work. You just need to ensure that a binary tree can be serialized to a string and this string can be deserialized to the original tree structure.\n\n**Clarification:** The input/output format is the same as how LeetCode serializes a binary tree. You do not necessarily need to follow this format, so please be creative and come up with different approaches yourself.", "_readme_examples": { "list": [ { "content": "![Example 1](https://assets.leetcode.com/uploads/2020/09/15/serdeser.jpg)\n\n```\nInput: root = [1,2,3,null,null,4,5]\nOutput: [1,2,3,null,null,4,5]\n```" }, - { "content": "```\nInput: root = []\nOutput: []\n```" } + { + "content": "```\nInput: root = []\nOutput: []\n```" + } ] }, "readme_constraints": "- The number of nodes in the tree is in the range [0, 10^4].\n- -1000 <= Node.val <= 1000", @@ -51,14 +55,34 @@ } ] }, - "_test_helper_methods": { "list": [] }, + "_test_helper_methods": { + "list": [] + }, "_test_methods": { "list": [ { "name": "test_serialize_deserialize", "signature": "(self, root_list: list[int | None])", "parametrize": "root_list", - "test_cases": "[([1, 2, 3, None, None, 4, 5]), ([]), ([1]), ([1, 2]), ([1, None, 2]), ([1, 2, 3, 4, 5, 6, 7]), ([5, 2, 3, None, None, 2, 4, 3, 1]), ([1, 2, 3]), ([1, None, None]), ([1, 2, None, 4]), ([1, None, 2, None, 3]), ([10, 5, 15, None, 6, 12, 20]), ([0, -1, 1]), ([100]), ([1, 2, 3, 4, None, None, 7, 8])]", + "test_cases": { + "list": [ + "([1, 2, 3, None, None, 4, 5])", + "([])", + "([1])", + "([1, 2])", + "([1, None, 2])", + "([1, 2, 3, 4, 5, 6, 7])", + "([5, 2, 3, None, None, 2, 4, 3, 1])", + "([1, 2, 3])", + "([1, None, None])", + "([1, 2, None, 4])", + "([1, None, 2, None, 3])", + "([10, 5, 15, None, 6, 12, 20])", + "([0, -1, 1])", + "([100])", + "([1, 2, 3, 4, None, None, 7, 8])" + ] + }, "body": " result = run_serialize_deserialize(Codec, root_list)\n assert_serialize_deserialize(result, root_list)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/set_matrix_zeroes.json b/leetcode_py/cli/resources/leetcode/json/problems/set_matrix_zeroes.json index b642d2e..5704cf0 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/set_matrix_zeroes.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/set_matrix_zeroes.json @@ -5,7 +5,9 @@ "problem_title": "Set Matrix Zeroes", "difficulty": "Medium", "topics": "Array, Hash Table, Matrix", - "_tags": { "list": ["blind-75"] }, + "_tags": { + "list": ["blind-75"] + }, "readme_description": "Given an `m x n` integer matrix `matrix`, if an element is `0`, set its entire row and column to `0`'s. You must do it in place.", "_readme_examples": { "list": [ @@ -44,7 +46,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -52,7 +60,25 @@ "name": "test_set_zeroes", "signature": "(self, matrix: list[list[int]], expected: list[list[int]])", "parametrize": "matrix, expected", - "test_cases": "[([[1,1,1],[1,0,1],[1,1,1]], [[1,0,1],[0,0,0],[1,0,1]]), ([[0,1,2,0],[3,4,5,2],[1,3,1,5]], [[0,0,0,0],[0,4,5,0],[0,3,1,0]]), ([[1]], [[1]]), ([[0]], [[0]]), ([[1,0]], [[0,0]]), ([[0,1]], [[0,0]]), ([[1,2,3],[4,5,6],[7,8,9]], [[1,2,3],[4,5,6],[7,8,9]]), ([[1,2,0],[4,5,6],[7,8,9]], [[0,0,0],[4,5,0],[7,8,0]]), ([[0,2,3],[4,5,6],[7,8,9]], [[0,0,0],[0,5,6],[0,8,9]]), ([[1,2,3],[4,0,6],[7,8,0]], [[1,0,0],[0,0,0],[0,0,0]]), ([[1,2],[0,4],[5,6]], [[0,2],[0,0],[0,6]]), ([[1,2,3],[4,5,6]], [[1,2,3],[4,5,6]]), ([[0,2,0],[4,5,6]], [[0,0,0],[0,5,0]]), ([[-1,2,3],[4,0,-6]], [[-1,0,3],[0,0,0]]), ([[1,2,3,4],[0,5,0,7],[8,9,10,11]], [[0,2,0,4],[0,0,0,0],[0,9,0,11]])]", + "test_cases": { + "list": [ + "([[1,1,1],[1,0,1],[1,1,1]], [[1,0,1],[0,0,0],[1,0,1]])", + "([[0,1,2,0],[3,4,5,2],[1,3,1,5]], [[0,0,0,0],[0,4,5,0],[0,3,1,0]])", + "([[1]], [[1]])", + "([[0]], [[0]])", + "([[1,0]], [[0,0]])", + "([[0,1]], [[0,0]])", + "([[1,2,3],[4,5,6],[7,8,9]], [[1,2,3],[4,5,6],[7,8,9]])", + "([[1,2,0],[4,5,6],[7,8,9]], [[0,0,0],[4,5,0],[7,8,0]])", + "([[0,2,3],[4,5,6],[7,8,9]], [[0,0,0],[0,5,6],[0,8,9]])", + "([[1,2,3],[4,0,6],[7,8,0]], [[1,0,0],[0,0,0],[0,0,0]])", + "([[1,2],[0,4],[5,6]], [[0,2],[0,0],[0,6]])", + "([[1,2,3],[4,5,6]], [[1,2,3],[4,5,6]])", + "([[0,2,0],[4,5,6]], [[0,0,0],[0,5,0]])", + "([[-1,2,3],[4,0,-6]], [[-1,0,3],[0,0,0]])", + "([[1,2,3,4],[0,5,0,7],[8,9,10,11]], [[0,2,0,4],[0,0,0,0],[0,9,0,11]])" + ] + }, "body": " result = run_set_zeroes(Solution, matrix)\n assert_set_zeroes(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/sort_colors.json b/leetcode_py/cli/resources/leetcode/json/problems/sort_colors.json index 1628617..56c26c2 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/sort_colors.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/sort_colors.json @@ -5,12 +5,18 @@ "problem_title": "Sort Colors", "difficulty": "Medium", "topics": "Array, Two Pointers, Sorting", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "Given an array `nums` with `n` objects colored red, white, or blue, sort them **in-place** so that objects of the same color are adjacent, with the colors in the order red, white, and blue.\n\nWe will use the integers `0`, `1`, and `2` to represent the color red, white, and blue, respectively.\n\nYou must solve this problem without using the library's sort function.", "_readme_examples": { "list": [ - { "content": "```\nInput: nums = [2,0,2,1,1,0]\nOutput: [0,0,1,1,2,2]\n```" }, - { "content": "```\nInput: nums = [2,0,1]\nOutput: [0,1,2]\n```" } + { + "content": "```\nInput: nums = [2,0,2,1,1,0]\nOutput: [0,0,1,1,2,2]\n```" + }, + { + "content": "```\nInput: nums = [2,0,1]\nOutput: [0,1,2]\n```" + } ] }, "readme_constraints": "- `n == nums.length`\n- `1 <= n <= 300`\n- `nums[i]` is either `0`, `1`, or `2`.", @@ -40,7 +46,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -48,7 +60,25 @@ "name": "test_sort_colors", "signature": "(self, nums: list[int], expected: list[int])", "parametrize": "nums, expected", - "test_cases": "[([2, 0, 2, 1, 1, 0], [0, 0, 1, 1, 2, 2]), ([2, 0, 1], [0, 1, 2]), ([0], [0]), ([1], [1]), ([2], [2]), ([0, 1, 2], [0, 1, 2]), ([2, 2, 2], [2, 2, 2]), ([0, 0, 0], [0, 0, 0]), ([1, 1, 1], [1, 1, 1]), ([2, 1, 0], [0, 1, 2]), ([1, 0, 2, 1, 0, 2], [0, 0, 1, 1, 2, 2]), ([0, 2, 1, 0, 2, 1], [0, 0, 1, 1, 2, 2]), ([2, 2, 1, 0, 0, 1], [0, 0, 1, 1, 2, 2]), ([1, 2, 0, 1, 2, 0, 1], [0, 0, 1, 1, 1, 2, 2]), ([0, 1, 0, 2, 1, 2, 0], [0, 0, 0, 1, 1, 2, 2])]", + "test_cases": { + "list": [ + "([2, 0, 2, 1, 1, 0], [0, 0, 1, 1, 2, 2])", + "([2, 0, 1], [0, 1, 2])", + "([0], [0])", + "([1], [1])", + "([2], [2])", + "([0, 1, 2], [0, 1, 2])", + "([2, 2, 2], [2, 2, 2])", + "([0, 0, 0], [0, 0, 0])", + "([1, 1, 1], [1, 1, 1])", + "([2, 1, 0], [0, 1, 2])", + "([1, 0, 2, 1, 0, 2], [0, 0, 1, 1, 2, 2])", + "([0, 2, 1, 0, 2, 1], [0, 0, 1, 1, 2, 2])", + "([2, 2, 1, 0, 0, 1], [0, 0, 1, 1, 2, 2])", + "([1, 2, 0, 1, 2, 0, 1], [0, 0, 1, 1, 1, 2, 2])", + "([0, 1, 0, 2, 1, 2, 0], [0, 0, 0, 1, 1, 2, 2])" + ] + }, "body": " result = run_sort_colors(Solution, nums)\n assert_sort_colors(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/spiral_matrix.json b/leetcode_py/cli/resources/leetcode/json/problems/spiral_matrix.json index 561dd75..f99b22e 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/spiral_matrix.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/spiral_matrix.json @@ -5,7 +5,9 @@ "problem_title": "Spiral Matrix", "difficulty": "Medium", "topics": "Array, Matrix, Simulation", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "Given an `m x n` matrix, return all elements of the matrix in spiral order.", "_readme_examples": { "list": [ @@ -44,7 +46,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -52,7 +60,24 @@ "name": "test_spiral_order", "signature": "(self, matrix: list[list[int]], expected: list[int])", "parametrize": "matrix, expected", - "test_cases": "[([[1,2,3],[4,5,6],[7,8,9]], [1,2,3,6,9,8,7,4,5]), ([[1,2,3,4],[5,6,7,8],[9,10,11,12]], [1,2,3,4,8,12,11,10,9,5,6,7]), ([[1]], [1]), ([[1,2]], [1,2]), ([[1],[2]], [1,2]), ([[1,2,3]], [1,2,3]), ([[1],[2],[3]], [1,2,3]), ([[1,2],[3,4]], [1,2,4,3]), ([[1,2,3,4,5]], [1,2,3,4,5]), ([[1],[2],[3],[4],[5]], [1,2,3,4,5]), ([[1,2,3],[4,5,6]], [1,2,3,6,5,4]), ([[1,2],[3,4],[5,6]], [1,2,4,6,5,3]), ([[7,9,6],[2,8,6],[1,3,5]], [7,9,6,6,5,3,1,2,8]), ([[1,2,3,4],[5,6,7,8]], [1,2,3,4,8,7,6,5])]", + "test_cases": { + "list": [ + "([[1,2,3],[4,5,6],[7,8,9]], [1,2,3,6,9,8,7,4,5])", + "([[1,2,3,4],[5,6,7,8],[9,10,11,12]], [1,2,3,4,8,12,11,10,9,5,6,7])", + "([[1]], [1])", + "([[1,2]], [1,2])", + "([[1],[2]], [1,2])", + "([[1,2,3]], [1,2,3])", + "([[1],[2],[3]], [1,2,3])", + "([[1,2],[3,4]], [1,2,4,3])", + "([[1,2,3,4,5]], [1,2,3,4,5])", + "([[1],[2],[3],[4],[5]], [1,2,3,4,5])", + "([[1,2,3],[4,5,6]], [1,2,3,6,5,4])", + "([[1,2],[3,4],[5,6]], [1,2,4,6,5,3])", + "([[7,9,6],[2,8,6],[1,3,5]], [7,9,6,6,5,3,1,2,8])", + "([[1,2,3,4],[5,6,7,8]], [1,2,3,4,8,7,6,5])" + ] + }, "body": " result = run_spiral_order(Solution, matrix)\n assert_spiral_order(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/string_to_integer_atoi.json b/leetcode_py/cli/resources/leetcode/json/problems/string_to_integer_atoi.json index 2cb7afa..9f911f3 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/string_to_integer_atoi.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/string_to_integer_atoi.json @@ -5,7 +5,9 @@ "problem_title": "String to Integer (atoi)", "difficulty": "Medium", "topics": "String", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "Implement the `my_atoi(string s)` function, which converts a string to a 32-bit signed integer.\n\nThe algorithm for `my_atoi(string s)` is as follows:\n\n1. **Whitespace**: Ignore any leading whitespace (` `).\n2. **Signedness**: Determine the sign by checking if the next character is `-` or `+`, assuming positivity if neither present.\n3. **Conversion**: Read the integer by skipping leading zeros until a non-digit character is encountered or the end of the string is reached. If no digits were read, then the result is 0.\n4. **Rounding**: If the integer is out of the 32-bit signed integer range `[-2^31, 2^31 - 1]`, then round the integer to remain in the range. Specifically, integers less than `-2^31` should be rounded to `-2^31`, and integers greater than `2^31 - 1` should be rounded to `2^31 - 1`.\n\nReturn the integer as the final result.", "_readme_examples": { "list": [ @@ -53,7 +55,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -61,7 +69,23 @@ "name": "test_my_atoi", "signature": "(self, s: str, expected: int)", "parametrize": "s, expected", - "test_cases": "[('42', 42), (' -042', -42), ('1337c0d3', 1337), ('0-1', 0), ('words and 987', 0), ('', 0), (' ', 0), ('+1', 1), ('-1', -1), ('2147483647', 2147483647), ('-2147483648', -2147483648), ('2147483648', 2147483647), ('-2147483649', -2147483648)]", + "test_cases": { + "list": [ + "('42', 42)", + "(' -042', -42)", + "('1337c0d3', 1337)", + "('0-1', 0)", + "('words and 987', 0)", + "('', 0)", + "(' ', 0)", + "('+1', 1)", + "('-1', -1)", + "('2147483647', 2147483647)", + "('-2147483648', -2147483648)", + "('2147483648', 2147483647)", + "('-2147483649', -2147483648)" + ] + }, "body": " result = run_my_atoi(Solution, s)\n assert_my_atoi(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/subsets.json b/leetcode_py/cli/resources/leetcode/json/problems/subsets.json index fe72687..049521a 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/subsets.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/subsets.json @@ -5,14 +5,18 @@ "problem_title": "Subsets", "difficulty": "Medium", "topics": "Array, Backtracking, Bit Manipulation", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "Given an integer array `nums` of **unique** elements, return *all possible* subsets (the power set).\n\nThe solution set **must not** contain duplicate subsets. Return the solution in **any order**.", "_readme_examples": { "list": [ { "content": "```\nInput: nums = [1,2,3]\nOutput: [[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]]\n```" }, - { "content": "```\nInput: nums = [0]\nOutput: [[],[0]]\n```" } + { + "content": "```\nInput: nums = [0]\nOutput: [[],[0]]\n```" + } ] }, "readme_constraints": "- 1 <= nums.length <= 10\n- -10 <= nums[i] <= 10\n- All the numbers of nums are unique.", @@ -42,7 +46,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -50,7 +60,22 @@ "name": "test_subsets", "signature": "(self, nums: list[int], expected: list[list[int]])", "parametrize": "nums, expected", - "test_cases": "[([1, 2, 3], [[], [1], [2], [1, 2], [3], [1, 3], [2, 3], [1, 2, 3]]), ([0], [[], [0]]), ([1], [[], [1]]), ([1, 2], [[], [1], [2], [1, 2]]), ([4, 1, 0], [[], [4], [4, 1], [4, 1, 0], [4, 0], [1], [1, 0], [0]]), ([-1, 0, 1], [[], [-1], [-1, 0], [-1, 0, 1], [-1, 1], [0], [0, 1], [1]]), ([5], [[], [5]]), ([2, 1, 3], [[], [2], [2, 1], [2, 1, 3], [2, 3], [1], [1, 3], [3]]), ([10], [[], [10]]), ([-10, 10], [[], [-10], [-10, 10], [10]]), ([1, 2, 3, 4], [[], [1], [1, 2], [1, 2, 3], [1, 2, 3, 4], [1, 2, 4], [1, 3], [1, 3, 4], [1, 4], [2], [2, 3], [2, 3, 4], [2, 4], [3], [3, 4], [4]]), ([5, 2], [[], [5], [5, 2], [2]])]", + "test_cases": { + "list": [ + "([1, 2, 3], [[], [1], [2], [1, 2], [3], [1, 3], [2, 3], [1, 2, 3]])", + "([0], [[], [0]])", + "([1], [[], [1]])", + "([1, 2], [[], [1], [2], [1, 2]])", + "([4, 1, 0], [[], [4], [4, 1], [4, 1, 0], [4, 0], [1], [1, 0], [0]])", + "([-1, 0, 1], [[], [-1], [-1, 0], [-1, 0, 1], [-1, 1], [0], [0, 1], [1]])", + "([5], [[], [5]])", + "([2, 1, 3], [[], [2], [2, 1], [2, 1, 3], [2, 3], [1], [1, 3], [3]])", + "([10], [[], [10]])", + "([-10, 10], [[], [-10], [-10, 10], [10]])", + "([1, 2, 3, 4], [[], [1], [1, 2], [1, 2, 3], [1, 2, 3, 4], [1, 2, 4], [1, 3], [1, 3, 4], [1, 4], [2], [2, 3], [2, 3, 4], [2, 4], [3], [3, 4], [4]])", + "([5, 2], [[], [5], [5, 2], [2]])" + ] + }, "body": " result = run_subsets(Solution, nums)\n assert_subsets(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/swap_nodes_in_pairs.json b/leetcode_py/cli/resources/leetcode/json/problems/swap_nodes_in_pairs.json index c6ff3ff..5e56087 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/swap_nodes_in_pairs.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/swap_nodes_in_pairs.json @@ -5,22 +5,28 @@ "problem_title": "Swap Nodes in Pairs", "difficulty": "Medium", "topics": "Linked List, Recursion", - "_tags": { "list": ["grind"] }, - + "_tags": { + "list": ["grind"] + }, "readme_description": "Given a linked list, swap every two adjacent nodes and return its head. You must solve the problem without modifying the values in the list's nodes (i.e., only nodes themselves may be changed.)", "_readme_examples": { "list": [ { "content": "![Example 1](https://assets.leetcode.com/uploads/2020/10/03/swap_ex1.jpg)\n\n```\nInput: head = [1,2,3,4]\nOutput: [2,1,4,3]\n```" }, - { "content": "```\nInput: head = []\nOutput: []\n```" }, - { "content": "```\nInput: head = [1]\nOutput: [1]\n```" }, - { "content": "```\nInput: head = [1,2,3]\nOutput: [2,1,3]\n```" } + { + "content": "```\nInput: head = []\nOutput: []\n```" + }, + { + "content": "```\nInput: head = [1]\nOutput: [1]\n```" + }, + { + "content": "```\nInput: head = [1,2,3]\nOutput: [2,1,3]\n```" + } ] }, "readme_constraints": "- The number of nodes in the list is in the range `[0, 100]`.\n- `0 <= Node.val <= 100`", "readme_additional": "", - "helpers_imports": "from leetcode_py import ListNode", "helpers_content": "", "helpers_run_name": "swap_pairs", @@ -29,16 +35,13 @@ "helpers_assert_name": "swap_pairs", "helpers_assert_signature": "(result: list[int], expected: list[int]) -> bool", "helpers_assert_body": " assert result == expected\n return True", - "solution_imports": "from leetcode_py import ListNode", "solution_contents": "", "solution_class_content": "", - "test_imports": "import pytest\nfrom leetcode_py import logged_test\nfrom .helpers import assert_swap_pairs, run_swap_pairs\nfrom .solution import Solution", "test_content": "", "test_class_name": "SwapNodesInPairs", "test_class_content": " def setup_method(self):\n self.solution = Solution()", - "_solution_methods": { "list": [ { @@ -48,23 +51,41 @@ } ] }, - "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, - "_test_methods": { "list": [ { "name": "test_swap_pairs", "signature": "(self, head_list: list[int], expected: list[int])", "parametrize": "head_list, expected", - "test_cases": "[([1, 2, 3, 4], [2, 1, 4, 3]), ([], []), ([1], [1]), ([1, 2, 3], [2, 1, 3]), ([1, 2], [2, 1]), ([1, 2, 3, 4, 5], [2, 1, 4, 3, 5]), ([1, 2, 3, 4, 5, 6], [2, 1, 4, 3, 6, 5]), ([5, 4, 3, 2, 1], [4, 5, 2, 3, 1]), ([10, 20], [20, 10]), ([100], [100]), ([0, 1, 2, 3], [1, 0, 3, 2]), ([7, 8, 9, 10, 11, 12, 13], [8, 7, 10, 9, 12, 11, 13])]", + "test_cases": { + "list": [ + "([1, 2, 3, 4], [2, 1, 4, 3])", + "([], [])", + "([1], [1])", + "([1, 2, 3], [2, 1, 3])", + "([1, 2], [2, 1])", + "([1, 2, 3, 4, 5], [2, 1, 4, 3, 5])", + "([1, 2, 3, 4, 5, 6], [2, 1, 4, 3, 6, 5])", + "([5, 4, 3, 2, 1], [4, 5, 2, 3, 1])", + "([10, 20], [20, 10])", + "([100], [100])", + "([0, 1, 2, 3], [1, 0, 3, 2])", + "([7, 8, 9, 10, 11, 12, 13], [8, 7, 10, 9, 12, 11, 13])" + ] + }, "body": " result = run_swap_pairs(Solution, head_list)\n assert_swap_pairs(result, expected)" } ] }, - "playground_imports": "from helpers import run_swap_pairs, assert_swap_pairs\nfrom solution import Solution\nfrom leetcode_py import ListNode", "playground_setup": "# Example test case\nhead_list = [1, 2, 3, 4]\nexpected = [2, 1, 4, 3]", "playground_run": "result = run_swap_pairs(Solution, head_list)\nresult", diff --git a/leetcode_py/cli/resources/leetcode/json/problems/task_scheduler.json b/leetcode_py/cli/resources/leetcode/json/problems/task_scheduler.json index 963ebfb..773389b 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/task_scheduler.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/task_scheduler.json @@ -5,7 +5,9 @@ "problem_title": "Task Scheduler", "difficulty": "Medium", "topics": "Array, Hash Table, Greedy, Sorting, Heap (Priority Queue), Counting", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "You are given an array of CPU `tasks`, each labeled with a letter from A to Z, and a number `n`. Each CPU interval can be idle or allow the completion of one task. Tasks can be completed in any order, but there's a constraint: there has to be a gap of **at least** `n` intervals between two tasks with the same label.\n\nReturn the **minimum** number of CPU intervals required to complete all tasks.", "_readme_examples": { "list": [ @@ -47,7 +49,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -55,7 +63,22 @@ "name": "test_least_interval", "signature": "(self, tasks: list[str], n: int, expected: int)", "parametrize": "tasks, n, expected", - "test_cases": "[(['A', 'A', 'A', 'B', 'B', 'B'], 2, 8), (['A', 'C', 'A', 'B', 'D', 'B'], 1, 6), (['A', 'A', 'A', 'B', 'B', 'B'], 3, 10), (['A'], 0, 1), (['A', 'A'], 1, 3), (['A', 'B'], 0, 2), (['A', 'A', 'A'], 0, 3), (['A', 'B', 'C', 'D', 'E', 'F'], 2, 6), (['A', 'A', 'A', 'A', 'A', 'A', 'B', 'C', 'D', 'E', 'F', 'G'], 2, 16), (['A', 'A', 'B', 'B'], 2, 5), (['A', 'B', 'A', 'B'], 1, 4), (['A', 'A', 'A', 'A'], 3, 13)]", + "test_cases": { + "list": [ + "(['A', 'A', 'A', 'B', 'B', 'B'], 2, 8)", + "(['A', 'C', 'A', 'B', 'D', 'B'], 1, 6)", + "(['A', 'A', 'A', 'B', 'B', 'B'], 3, 10)", + "(['A'], 0, 1)", + "(['A', 'A'], 1, 3)", + "(['A', 'B'], 0, 2)", + "(['A', 'A', 'A'], 0, 3)", + "(['A', 'B', 'C', 'D', 'E', 'F'], 2, 6)", + "(['A', 'A', 'A', 'A', 'A', 'A', 'B', 'C', 'D', 'E', 'F', 'G'], 2, 16)", + "(['A', 'A', 'B', 'B'], 2, 5)", + "(['A', 'B', 'A', 'B'], 1, 4)", + "(['A', 'A', 'A', 'A'], 3, 13)" + ] + }, "body": " result = run_least_interval(Solution, tasks, n)\n assert_least_interval(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/three_sum.json b/leetcode_py/cli/resources/leetcode/json/problems/three_sum.json index ed261d7..f162621 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/three_sum.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/three_sum.json @@ -5,7 +5,9 @@ "problem_title": "3Sum", "difficulty": "Medium", "topics": "Array, Two Pointers, Sorting", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "Given an integer array `nums`, return all the triplets `[nums[i], nums[j], nums[k]]` such that `i != j`, `i != k`, and `j != k`, and `nums[i] + nums[j] + nums[k] == 0`.\n\nNotice that the solution set must not contain duplicate triplets.", "_readme_examples": { "list": [ @@ -47,7 +49,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -55,7 +63,22 @@ "name": "test_three_sum", "signature": "(self, nums: list[int], expected: list[list[int]])", "parametrize": "nums, expected", - "test_cases": "[([-1, 0, 1, 2, -1, -4], [[-1, -1, 2], [-1, 0, 1]]), ([0, 1, 1], []), ([0, 0, 0], [[0, 0, 0]]), ([-1, 0, 1], [[-1, 0, 1]]), ([1, 2, -2, -1], []), ([-2, 0, 1, 1, 2], [[-2, 0, 2], [-2, 1, 1]]), ([1, -1, -1, 0], [[-1, 0, 1]]), ([-4, -2, -2, -2, 0, 1, 2, 2, 2, 3, 3, 4, 4, 6, 6], [[-4, -2, 6], [-4, 0, 4], [-4, 1, 3], [-4, 2, 2], [-2, -2, 4], [-2, 0, 2]]), ([3, 0, -2, -1, 1, 2], [[-2, -1, 3], [-2, 0, 2], [-1, 0, 1]]), ([0, 0, 0, 0], [[0, 0, 0]]), ([-1, -1, 2], [[-1, -1, 2]]), ([1, 1, -2], [[-2, 1, 1]])]", + "test_cases": { + "list": [ + "([-1, 0, 1, 2, -1, -4], [[-1, -1, 2], [-1, 0, 1]])", + "([0, 1, 1], [])", + "([0, 0, 0], [[0, 0, 0]])", + "([-1, 0, 1], [[-1, 0, 1]])", + "([1, 2, -2, -1], [])", + "([-2, 0, 1, 1, 2], [[-2, 0, 2], [-2, 1, 1]])", + "([1, -1, -1, 0], [[-1, 0, 1]])", + "([-4, -2, -2, -2, 0, 1, 2, 2, 2, 3, 3, 4, 4, 6, 6], [[-4, -2, 6], [-4, 0, 4], [-4, 1, 3], [-4, 2, 2], [-2, -2, 4], [-2, 0, 2]])", + "([3, 0, -2, -1, 1, 2], [[-2, -1, 3], [-2, 0, 2], [-1, 0, 1]])", + "([0, 0, 0, 0], [[0, 0, 0]])", + "([-1, -1, 2], [[-1, -1, 2]])", + "([1, 1, -2], [[-2, 1, 1]])" + ] + }, "body": " result = run_three_sum(Solution, nums)\n assert_three_sum(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/time_based_key_value_store.json b/leetcode_py/cli/resources/leetcode/json/problems/time_based_key_value_store.json index 1b4be43..1cffff7 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/time_based_key_value_store.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/time_based_key_value_store.json @@ -5,7 +5,9 @@ "problem_title": "Time Based Key-Value Store", "difficulty": "Medium", "topics": "Hash Table, String, Binary Search, Design", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "Design a time-based key-value data structure that can store multiple values for the same key at different time stamps and retrieve the key's value at a certain timestamp.\n\nImplement the `TimeMap` class:\n\n- `TimeMap()` Initializes the object of the data structure.\n- `void set(String key, String value, int timestamp)` Stores the key `key` with the value `value` at the given time `timestamp`.\n- `String get(String key, int timestamp)` Returns a value such that `set` was called previously, with `timestamp_prev <= timestamp`. If there are multiple such values, it returns the value associated with the largest `timestamp_prev`. If there are no values, it returns `\"\"`.", "_readme_examples": { "list": [ @@ -50,14 +52,31 @@ } ] }, - "_test_helper_methods": { "list": [] }, + "_test_helper_methods": { + "list": [] + }, "_test_methods": { "list": [ { "name": "test_time_map_operations", "signature": "(self, operations: list[str], inputs: list[list], expected: list)", "parametrize": "operations, inputs, expected", - "test_cases": "[(['TimeMap', 'set', 'get', 'get', 'set', 'get', 'get'], [[], ['foo', 'bar', 1], ['foo', 1], ['foo', 3], ['foo', 'bar2', 4], ['foo', 4], ['foo', 5]], [None, None, 'bar', 'bar', None, 'bar2', 'bar2']), (['TimeMap', 'get'], [[], ['key', 1]], [None, '']), (['TimeMap', 'set', 'get'], [[], ['a', 'val', 1], ['a', 1]], [None, None, 'val']), (['TimeMap', 'set', 'get', 'get'], [[], ['key', 'value', 5], ['key', 3], ['key', 7]], [None, None, '', 'value']), (['TimeMap', 'set', 'set', 'get', 'get', 'get'], [[], ['x', 'v1', 1], ['x', 'v2', 2], ['x', 1], ['x', 2], ['x', 3]], [None, None, None, 'v1', 'v2', 'v2']), (['TimeMap', 'set', 'set', 'set', 'get', 'get', 'get'], [[], ['k', 'a', 10], ['k', 'b', 20], ['k', 'c', 30], ['k', 15], ['k', 25], ['k', 35]], [None, None, None, None, 'a', 'b', 'c']), (['TimeMap', 'set', 'set', 'get', 'get'], [[], ['key1', 'val1', 1], ['key2', 'val2', 2], ['key1', 1], ['key2', 2]], [None, None, None, 'val1', 'val2']), (['TimeMap', 'set', 'set', 'set', 'get', 'get', 'get'], [[], ['a', 'x', 1], ['b', 'y', 2], ['c', 'z', 3], ['a', 1], ['b', 2], ['c', 3]], [None, None, None, None, 'x', 'y', 'z']), (['TimeMap', 'set', 'get', 'set', 'get', 'set', 'get'], [[], ['test', 'first', 1], ['test', 1], ['test', 'second', 100], ['test', 50], ['test', 'third', 1000], ['test', 500]], [None, None, 'first', None, 'first', None, 'second']), (['TimeMap', 'set', 'set', 'set', 'set', 'get'], [[], ['data', 'v1', 1], ['data', 'v2', 10], ['data', 'v3', 100], ['data', 'v4', 1000], ['data', 555]], [None, None, None, None, None, 'v3']), (['TimeMap', 'set', 'get', 'get', 'get'], [[], ['single', 'value', 42], ['single', 1], ['single', 42], ['single', 100]], [None, None, '', 'value', 'value']), (['TimeMap', 'set', 'set', 'get', 'get', 'get', 'get'], [[], ['boundary', 'min', 1], ['boundary', 'max', 10000000], ['boundary', 0], ['boundary', 1], ['boundary', 5000000], ['boundary', 10000000]], [None, None, None, '', 'min', 'min', 'max'])]", + "test_cases": { + "list": [ + "(['TimeMap', 'set', 'get', 'get', 'set', 'get', 'get'], [[], ['foo', 'bar', 1], ['foo', 1], ['foo', 3], ['foo', 'bar2', 4], ['foo', 4], ['foo', 5]], [None, None, 'bar', 'bar', None, 'bar2', 'bar2'])", + "(['TimeMap', 'get'], [[], ['key', 1]], [None, ''])", + "(['TimeMap', 'set', 'get'], [[], ['a', 'val', 1], ['a', 1]], [None, None, 'val'])", + "(['TimeMap', 'set', 'get', 'get'], [[], ['key', 'value', 5], ['key', 3], ['key', 7]], [None, None, '', 'value'])", + "(['TimeMap', 'set', 'set', 'get', 'get', 'get'], [[], ['x', 'v1', 1], ['x', 'v2', 2], ['x', 1], ['x', 2], ['x', 3]], [None, None, None, 'v1', 'v2', 'v2'])", + "(['TimeMap', 'set', 'set', 'set', 'get', 'get', 'get'], [[], ['k', 'a', 10], ['k', 'b', 20], ['k', 'c', 30], ['k', 15], ['k', 25], ['k', 35]], [None, None, None, None, 'a', 'b', 'c'])", + "(['TimeMap', 'set', 'set', 'get', 'get'], [[], ['key1', 'val1', 1], ['key2', 'val2', 2], ['key1', 1], ['key2', 2]], [None, None, None, 'val1', 'val2'])", + "(['TimeMap', 'set', 'set', 'set', 'get', 'get', 'get'], [[], ['a', 'x', 1], ['b', 'y', 2], ['c', 'z', 3], ['a', 1], ['b', 2], ['c', 3]], [None, None, None, None, 'x', 'y', 'z'])", + "(['TimeMap', 'set', 'get', 'set', 'get', 'set', 'get'], [[], ['test', 'first', 1], ['test', 1], ['test', 'second', 100], ['test', 50], ['test', 'third', 1000], ['test', 500]], [None, None, 'first', None, 'first', None, 'second'])", + "(['TimeMap', 'set', 'set', 'set', 'set', 'get'], [[], ['data', 'v1', 1], ['data', 'v2', 10], ['data', 'v3', 100], ['data', 'v4', 1000], ['data', 555]], [None, None, None, None, None, 'v3'])", + "(['TimeMap', 'set', 'get', 'get', 'get'], [[], ['single', 'value', 42], ['single', 1], ['single', 42], ['single', 100]], [None, None, '', 'value', 'value'])", + "(['TimeMap', 'set', 'set', 'get', 'get', 'get', 'get'], [[], ['boundary', 'min', 1], ['boundary', 'max', 10000000], ['boundary', 0], ['boundary', 1], ['boundary', 5000000], ['boundary', 10000000]], [None, None, None, '', 'min', 'min', 'max'])" + ] + }, "body": " result = run_time_map_operations(TimeMap, operations, inputs)\n assert_time_map_operations(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/top_k_frequent_words.json b/leetcode_py/cli/resources/leetcode/json/problems/top_k_frequent_words.json index 54aa4fc..f7aa424 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/top_k_frequent_words.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/top_k_frequent_words.json @@ -5,7 +5,9 @@ "problem_title": "Top K Frequent Words", "difficulty": "Medium", "topics": "Array, Hash Table, String, Trie, Sorting, Heap (Priority Queue), Bucket Sort, Counting", - "_tags": { "list": ["grind"] }, + "_tags": { + "list": ["grind"] + }, "readme_description": "Given an array of strings `words` and an integer `k`, return *the* `k` *most frequent strings*.\n\nReturn the answer **sorted** by **the frequency** from highest to lowest. Sort the words with the same frequency by their **lexicographical order**.", "_readme_examples": { "list": [ @@ -44,7 +46,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -52,7 +60,28 @@ "name": "test_top_k_frequent", "signature": "(self, words: list[str], k: int, expected: list[str])", "parametrize": "words, k, expected", - "test_cases": "[(['i', 'love', 'leetcode', 'i', 'love', 'coding'], 2, ['i', 'love']), (['the', 'day', 'is', 'sunny', 'the', 'the', 'the', 'sunny', 'is', 'is'], 4, ['the', 'is', 'sunny', 'day']), (['a', 'aa', 'aaa'], 1, ['a']), (['a', 'aa', 'aaa'], 2, ['a', 'aa']), (['a', 'aa', 'aaa'], 3, ['a', 'aa', 'aaa']), (['apple', 'banana', 'apple'], 1, ['apple']), (['apple', 'banana', 'apple'], 2, ['apple', 'banana']), (['word', 'word', 'word'], 1, ['word']), (['a', 'b', 'c', 'd', 'e'], 3, ['a', 'b', 'c']), (['hello', 'world', 'hello'], 2, ['hello', 'world']), (['cat', 'dog', 'cat', 'dog', 'bird'], 2, ['cat', 'dog']), (['x', 'y', 'z', 'x', 'y', 'x'], 2, ['x', 'y']), (['test'], 1, ['test']), (['a', 'b', 'a', 'c', 'b', 'a'], 3, ['a', 'b', 'c']), (['python', 'java', 'python', 'cpp', 'java', 'python'], 3, ['python', 'java', 'cpp']), (['one', 'two', 'three', 'one', 'two', 'one'], 2, ['one', 'two']), (['red', 'blue', 'green', 'red', 'blue', 'red'], 3, ['red', 'blue', 'green']), (['same', 'same', 'same', 'same'], 1, ['same'])]", + "test_cases": { + "list": [ + "(['i', 'love', 'leetcode', 'i', 'love', 'coding'], 2, ['i', 'love'])", + "(['the', 'day', 'is', 'sunny', 'the', 'the', 'the', 'sunny', 'is', 'is'], 4, ['the', 'is', 'sunny', 'day'])", + "(['a', 'aa', 'aaa'], 1, ['a'])", + "(['a', 'aa', 'aaa'], 2, ['a', 'aa'])", + "(['a', 'aa', 'aaa'], 3, ['a', 'aa', 'aaa'])", + "(['apple', 'banana', 'apple'], 1, ['apple'])", + "(['apple', 'banana', 'apple'], 2, ['apple', 'banana'])", + "(['word', 'word', 'word'], 1, ['word'])", + "(['a', 'b', 'c', 'd', 'e'], 3, ['a', 'b', 'c'])", + "(['hello', 'world', 'hello'], 2, ['hello', 'world'])", + "(['cat', 'dog', 'cat', 'dog', 'bird'], 2, ['cat', 'dog'])", + "(['x', 'y', 'z', 'x', 'y', 'x'], 2, ['x', 'y'])", + "(['test'], 1, ['test'])", + "(['a', 'b', 'a', 'c', 'b', 'a'], 3, ['a', 'b', 'c'])", + "(['python', 'java', 'python', 'cpp', 'java', 'python'], 3, ['python', 'java', 'cpp'])", + "(['one', 'two', 'three', 'one', 'two', 'one'], 2, ['one', 'two'])", + "(['red', 'blue', 'green', 'red', 'blue', 'red'], 3, ['red', 'blue', 'green'])", + "(['same', 'same', 'same', 'same'], 1, ['same'])" + ] + }, "body": " result = run_top_k_frequent(Solution, words, k)\n assert_top_k_frequent(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/trapping_rain_water.json b/leetcode_py/cli/resources/leetcode/json/problems/trapping_rain_water.json index d72b4ae..b8adc91 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/trapping_rain_water.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/trapping_rain_water.json @@ -5,14 +5,18 @@ "problem_title": "Trapping Rain Water", "difficulty": "Hard", "topics": "Array, Two Pointers, Dynamic Programming, Stack, Monotonic Stack", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "Given `n` non-negative integers representing an elevation map where the width of each bar is `1`, compute how much water it can trap after raining.", "_readme_examples": { "list": [ { "content": "![Example 1](https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png)\n\n```\nInput: height = [0,1,0,2,1,0,1,3,2,1,2,1]\nOutput: 6\n```\n**Explanation:** The above elevation map (black section) is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water (blue section) are being trapped." }, - { "content": "```\nInput: height = [4,2,0,3,2,5]\nOutput: 9\n```" } + { + "content": "```\nInput: height = [4,2,0,3,2,5]\nOutput: 9\n```" + } ] }, "readme_constraints": "- `n == height.length`\n- `1 <= n <= 2 * 10^4`\n- `0 <= height[i] <= 10^5`", @@ -42,7 +46,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -50,7 +60,25 @@ "name": "test_trap", "signature": "(self, height: list[int], expected: int)", "parametrize": "height, expected", - "test_cases": "[([0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1], 6), ([4, 2, 0, 3, 2, 5], 9), ([3, 0, 2, 0, 4], 7), ([0], 0), ([1], 0), ([1, 2], 0), ([2, 1], 0), ([3, 2, 0, 4], 4), ([5, 4, 1, 2], 1), ([2, 0, 2], 2), ([1, 0, 1], 1), ([0, 2, 0], 0), ([1, 2, 1], 0), ([5, 2, 7, 2, 6, 1, 5, 3, 2, 1], 11), ([0, 0, 0, 0], 0)]", + "test_cases": { + "list": [ + "([0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1], 6)", + "([4, 2, 0, 3, 2, 5], 9)", + "([3, 0, 2, 0, 4], 7)", + "([0], 0)", + "([1], 0)", + "([1, 2], 0)", + "([2, 1], 0)", + "([3, 2, 0, 4], 4)", + "([5, 4, 1, 2], 1)", + "([2, 0, 2], 2)", + "([1, 0, 1], 1)", + "([0, 2, 0], 0)", + "([1, 2, 1], 0)", + "([5, 2, 7, 2, 6, 1, 5, 3, 2, 1], 11)", + "([0, 0, 0, 0], 0)" + ] + }, "body": " result = run_trap(Solution, height)\n assert_trap(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/two_sum.json b/leetcode_py/cli/resources/leetcode/json/problems/two_sum.json index c79d490..86875e0 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/two_sum.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/two_sum.json @@ -5,15 +5,21 @@ "problem_title": "Two Sum", "difficulty": "Easy", "topics": "Array, Hash Table", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "Given an array of integers `nums` and an integer `target`, return indices of the two numbers such that they add up to `target`.\n\nYou may assume that each input would have exactly one solution, and you may not use the same element twice.\n\nYou can return the answer in any order.", "_readme_examples": { "list": [ { "content": "```\nInput: nums = [2,7,11,15], target = 9\nOutput: [0,1]\n```\n**Explanation:** Because nums[0] + nums[1] == 9, we return [0, 1]." }, - { "content": "```\nInput: nums = [3,2,4], target = 6\nOutput: [1,2]\n```" }, - { "content": "```\nInput: nums = [3,3], target = 6\nOutput: [0,1]\n```" } + { + "content": "```\nInput: nums = [3,2,4], target = 6\nOutput: [1,2]\n```" + }, + { + "content": "```\nInput: nums = [3,3], target = 6\nOutput: [0,1]\n```" + } ] }, "readme_constraints": "- 2 <= nums.length <= 10^4\n- -10^9 <= nums[i] <= 10^9\n- -10^9 <= target <= 10^9\n- Only one valid answer exists.", @@ -43,7 +49,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -51,7 +63,28 @@ "name": "test_two_sum", "signature": "(self, nums: list[int], target: int, expected: list[int])", "parametrize": "nums, target, expected", - "test_cases": "[([2, 7, 11, 15], 9, [0, 1]), ([3, 2, 4], 6, [1, 2]), ([3, 3], 6, [0, 1]), ([2, 5, 5, 11], 10, [1, 2]), ([1, 2, 3, 4, 5], 8, [2, 4]), ([0, 4, 3, 0], 0, [0, 3]), ([-1, -2, -3, -4, -5], -8, [2, 4]), ([1, 3, 4, 2], 6, [2, 3]), ([5, 75, 25], 100, [1, 2]), ([-3, 4, 3, 90], 0, [0, 2]), ([1, 1, 1, 1, 1, 4, 1, 1, 1, 1, 1, 2], 6, [5, 11]), ([2, 1, 9, 4, 4, 56, 90, 3], 8, [3, 4]), ([89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99], 185, [3, 4]), ([-1000000000, 1000000000], 0, [0, 1]), ([0, 1], 1, [0, 1]), ([1, 2], 5, []), ([3, 5, 7], 1, []), ([10, 20, 30], 15, [])]", + "test_cases": { + "list": [ + "([2, 7, 11, 15], 9, [0, 1])", + "([3, 2, 4], 6, [1, 2])", + "([3, 3], 6, [0, 1])", + "([2, 5, 5, 11], 10, [1, 2])", + "([1, 2, 3, 4, 5], 8, [2, 4])", + "([0, 4, 3, 0], 0, [0, 3])", + "([-1, -2, -3, -4, -5], -8, [2, 4])", + "([1, 3, 4, 2], 6, [2, 3])", + "([5, 75, 25], 100, [1, 2])", + "([-3, 4, 3, 90], 0, [0, 2])", + "([1, 1, 1, 1, 1, 4, 1, 1, 1, 1, 1, 2], 6, [5, 11])", + "([2, 1, 9, 4, 4, 56, 90, 3], 8, [3, 4])", + "([89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99], 185, [3, 4])", + "([-1000000000, 1000000000], 0, [0, 1])", + "([0, 1], 1, [0, 1])", + "([1, 2], 5, [])", + "([3, 5, 7], 1, [])", + "([10, 20, 30], 15, [])" + ] + }, "body": " result = run_two_sum(Solution, nums, target)\n assert_two_sum(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/unique_paths.json b/leetcode_py/cli/resources/leetcode/json/problems/unique_paths.json index afca70e..5626d00 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/unique_paths.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/unique_paths.json @@ -5,7 +5,9 @@ "problem_title": "Unique Paths", "difficulty": "Medium", "topics": "Math, Dynamic Programming, Combinatorics", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "There is a robot on an `m x n` grid. The robot is initially located at the **top-left corner** (i.e., `grid[0][0]`). The robot tries to move to the **bottom-right corner** (i.e., `grid[m - 1][n - 1]`). The robot can only move either down or right at any point in time.\n\nGiven the two integers `m` and `n`, return *the number of possible unique paths that the robot can take to reach the bottom-right corner*.\n\nThe test cases are generated so that the answer will be less than or equal to `2 * 10^9`.", "_readme_examples": { "list": [ @@ -44,7 +46,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -52,7 +60,25 @@ "name": "test_unique_paths", "signature": "(self, m: int, n: int, expected: int)", "parametrize": "m, n, expected", - "test_cases": "[(3, 7, 28), (3, 2, 3), (1, 1, 1), (1, 10, 1), (10, 1, 1), (2, 2, 2), (3, 3, 6), (4, 4, 20), (5, 5, 70), (2, 3, 3), (3, 4, 10), (4, 5, 35), (6, 3, 21), (7, 3, 28), (10, 10, 48620)]", + "test_cases": { + "list": [ + "(3, 7, 28)", + "(3, 2, 3)", + "(1, 1, 1)", + "(1, 10, 1)", + "(10, 1, 1)", + "(2, 2, 2)", + "(3, 3, 6)", + "(4, 4, 20)", + "(5, 5, 70)", + "(2, 3, 3)", + "(3, 4, 10)", + "(4, 5, 35)", + "(6, 3, 21)", + "(7, 3, 28)", + "(10, 10, 48620)" + ] + }, "body": " result = run_unique_paths(Solution, m, n)\n assert_unique_paths(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/valid_anagram.json b/leetcode_py/cli/resources/leetcode/json/problems/valid_anagram.json index 36e12bc..3f149d2 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/valid_anagram.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/valid_anagram.json @@ -5,12 +5,18 @@ "problem_title": "Valid Anagram", "difficulty": "Easy", "topics": "Hash Table, String, Sorting", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "Given two strings `s` and `t`, return `true` if `t` is an anagram of `s`, and `false` otherwise.", "_readme_examples": { "list": [ - { "content": "```\nInput: s = \"anagram\", t = \"nagaram\"\nOutput: true\n```" }, - { "content": "```\nInput: s = \"rat\", t = \"car\"\nOutput: false\n```" } + { + "content": "```\nInput: s = \"anagram\", t = \"nagaram\"\nOutput: true\n```" + }, + { + "content": "```\nInput: s = \"rat\", t = \"car\"\nOutput: false\n```" + } ] }, "readme_constraints": "- 1 <= s.length, t.length <= 5 * 10^4\n- s and t consist of lowercase English letters.", @@ -40,7 +46,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -48,7 +60,28 @@ "name": "test_is_anagram", "signature": "(self, s: str, t: str, expected: bool)", "parametrize": "s, t, expected", - "test_cases": "[('anagram', 'nagaram', True), ('rat', 'car', False), ('listen', 'silent', True), ('hello', 'bello', False), ('', '', True), ('a', 'a', True), ('a', 'b', False), ('ab', 'ba', True), ('abc', 'bca', True), ('abc', 'def', False), ('aab', 'abb', False), ('aabbcc', 'abcabc', True), ('abcd', 'abcde', False), ('race', 'care', True), ('elbow', 'below', True), ('study', 'dusty', True), ('night', 'thing', True), ('stressed', 'desserts', True)]", + "test_cases": { + "list": [ + "('anagram', 'nagaram', True)", + "('rat', 'car', False)", + "('listen', 'silent', True)", + "('hello', 'bello', False)", + "('', '', True)", + "('a', 'a', True)", + "('a', 'b', False)", + "('ab', 'ba', True)", + "('abc', 'bca', True)", + "('abc', 'def', False)", + "('aab', 'abb', False)", + "('aabbcc', 'abcabc', True)", + "('abcd', 'abcde', False)", + "('race', 'care', True)", + "('elbow', 'below', True)", + "('study', 'dusty', True)", + "('night', 'thing', True)", + "('stressed', 'desserts', True)" + ] + }, "body": " result = run_is_anagram(Solution, s, t)\n assert_is_anagram(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/valid_palindrome.json b/leetcode_py/cli/resources/leetcode/json/problems/valid_palindrome.json index 69ad19e..bb1a690 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/valid_palindrome.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/valid_palindrome.json @@ -5,7 +5,9 @@ "problem_title": "Valid Palindrome", "difficulty": "Easy", "topics": "Two Pointers, String", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "A phrase is a **palindrome** if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward. Alphanumeric characters include letters and numbers.\n\nGiven a string `s`, return `true` if it is a **palindrome**, or `false` otherwise.", "_readme_examples": { "list": [ @@ -47,7 +49,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -55,7 +63,26 @@ "name": "test_is_palindrome", "signature": "(self, s: str, expected: bool)", "parametrize": "s, expected", - "test_cases": "[(\"A man, a plan, a canal: Panama\", True), (\"race a car\", False), (\" \", True), (\"\", True), (\"a\", True), (\"Madam\", True), (\"No 'x' in Nixon\", True), (\"Mr. Owl ate my metal worm\", True), (\"Was it a car or a cat I saw?\", True), (\"Madam, I'm Adam\", True), (\"Never odd or even\", True), (\"Do geese see God?\", True), (\"Step on no pets\", True), (\"12321\", True), (\"hello\", False), (\"ab\", False)]", + "test_cases": { + "list": [ + "(\"A man, a plan, a canal: Panama\", True)", + "(\"race a car\", False)", + "(\" \", True)", + "(\"\", True)", + "(\"a\", True)", + "(\"Madam\", True)", + "(\"No 'x' in Nixon\", True)", + "(\"Mr. Owl ate my metal worm\", True)", + "(\"Was it a car or a cat I saw?\", True)", + "(\"Madam, I'm Adam\", True)", + "(\"Never odd or even\", True)", + "(\"Do geese see God?\", True)", + "(\"Step on no pets\", True)", + "(\"12321\", True)", + "(\"hello\", False)", + "(\"ab\", False)" + ] + }, "body": " result = run_is_palindrome(Solution, s)\n assert_is_palindrome(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/valid_parentheses.json b/leetcode_py/cli/resources/leetcode/json/problems/valid_parentheses.json index 81b406c..ac00c84 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/valid_parentheses.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/valid_parentheses.json @@ -5,15 +5,27 @@ "problem_title": "Valid Parentheses", "difficulty": "Easy", "topics": "String, Stack", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "Given a string `s` containing just the characters `'('`, `')'`, `'{'`, `'}'`, `'['` and `']'`, determine if the input string is valid.\n\nAn input string is valid if:\n\n1. Open brackets must be closed by the same type of brackets.\n2. Open brackets must be closed in the correct order.\n3. Every close bracket has a corresponding open bracket of the same type.", "_readme_examples": { "list": [ - { "content": "```\nInput: s = \"()\"\nOutput: true\n```" }, - { "content": "```\nInput: s = \"()[]{}\"\nOutput: true\n```" }, - { "content": "```\nInput: s = \"(]\"\nOutput: false\n```" }, - { "content": "```\nInput: s = \"([])\"\nOutput: true\n```" }, - { "content": "```\nInput: s = \"([)]\"\nOutput: false\n```" } + { + "content": "```\nInput: s = \"()\"\nOutput: true\n```" + }, + { + "content": "```\nInput: s = \"()[]{}\"\nOutput: true\n```" + }, + { + "content": "```\nInput: s = \"(]\"\nOutput: false\n```" + }, + { + "content": "```\nInput: s = \"([])\"\nOutput: true\n```" + }, + { + "content": "```\nInput: s = \"([)]\"\nOutput: false\n```" + } ] }, "readme_constraints": "- `1 <= s.length <= 10^4`\n- `s` consists of parentheses only `'()[]{}'`.", @@ -43,7 +55,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -51,7 +69,30 @@ "name": "test_is_valid", "signature": "(self, s: str, expected: bool)", "parametrize": "s, expected", - "test_cases": "[('()', True), ('()[]{}', True), ('(]', False), ('([])', True), ('([)]', False), ('', True), ('(', False), (')', False), ('{[()]}', True), ('{[(])}', False), ('((', False), ('))', False), ('([{}])', True), ('([{]})', False), ('{[}]', False), ('((()))', True), ('((())', False), ('(){}[]', True), ('{[(', False), (']})', False)]", + "test_cases": { + "list": [ + "('()', True)", + "('()[]{}', True)", + "('(]', False)", + "('([])', True)", + "('([)]', False)", + "('', True)", + "('(', False)", + "(')', False)", + "('{[()]}', True)", + "('{[(])}', False)", + "('((', False)", + "('))', False)", + "('([{}])', True)", + "('([{]})', False)", + "('{[}]', False)", + "('((()))', True)", + "('((())', False)", + "('(){}[]', True)", + "('{[(', False)", + "(']})', False)" + ] + }, "body": " result = run_is_valid(Solution, s)\n assert_is_valid(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/valid_sudoku.json b/leetcode_py/cli/resources/leetcode/json/problems/valid_sudoku.json index f255bcb..cbab66c 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/valid_sudoku.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/valid_sudoku.json @@ -5,10 +5,10 @@ "problem_title": "Valid Sudoku", "difficulty": "Medium", "topics": "Array, Hash Table, Matrix", - "_tags": { "list": ["grind"] }, - + "_tags": { + "list": ["grind"] + }, "readme_description": "Determine if a `9 x 9` Sudoku board is valid. Only the filled cells need to be validated **according to the following rules**:\n\n1. Each row must contain the digits `1-9` without repetition.\n2. Each column must contain the digits `1-9` without repetition.\n3. Each of the nine `3 x 3` sub-boxes of the grid must contain the digits `1-9` without repetition.\n\n**Note:**\n\n- A Sudoku board (partially filled) could be valid but is not necessarily solvable.\n- Only the filled cells need to be validated according to the mentioned rules.", - "_readme_examples": { "list": [ { @@ -19,9 +19,7 @@ } ] }, - "readme_constraints": "- `board.length == 9`\n- `board[i].length == 9`\n- `board[i][j]` is a digit `1-9` or `'.'`.", - "helpers_imports": "", "helpers_content": "", "helpers_run_name": "is_valid_sudoku", @@ -30,16 +28,13 @@ "helpers_assert_name": "is_valid_sudoku", "helpers_assert_signature": "(result: bool, expected: bool) -> bool", "helpers_assert_body": " assert result == expected\n return True", - "solution_imports": "", "solution_contents": "", "solution_class_content": "", - "test_imports": "import pytest\nfrom leetcode_py import logged_test\nfrom .helpers import assert_is_valid_sudoku, run_is_valid_sudoku\nfrom .solution import Solution", "test_content": "", "test_class_name": "ValidSudoku", "test_class_content": " def setup_method(self):\n self.solution = Solution()", - "_solution_methods": { "list": [ { @@ -49,23 +44,45 @@ } ] }, - "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, - "_test_methods": { "list": [ { "name": "test_is_valid_sudoku", "signature": "(self, board: list[list[str]], expected: bool)", "parametrize": "board, expected", - "test_cases": "[([['5', '3', '.', '.', '7', '.', '.', '.', '.'], ['6', '.', '.', '1', '9', '5', '.', '.', '.'], ['.', '9', '8', '.', '.', '.', '.', '6', '.'], ['8', '.', '.', '.', '6', '.', '.', '.', '3'], ['4', '.', '.', '8', '.', '3', '.', '.', '1'], ['7', '.', '.', '.', '2', '.', '.', '.', '6'], ['.', '6', '.', '.', '.', '.', '2', '8', '.'], ['.', '.', '.', '4', '1', '9', '.', '.', '5'], ['.', '.', '.', '.', '8', '.', '.', '7', '9']], True), ([['8', '3', '.', '.', '7', '.', '.', '.', '.'], ['6', '.', '.', '1', '9', '5', '.', '.', '.'], ['.', '9', '8', '.', '.', '.', '.', '6', '.'], ['8', '.', '.', '.', '6', '.', '.', '.', '3'], ['4', '.', '.', '8', '.', '3', '.', '.', '1'], ['7', '.', '.', '.', '2', '.', '.', '.', '6'], ['.', '6', '.', '.', '.', '.', '2', '8', '.'], ['.', '.', '.', '4', '1', '9', '.', '.', '5'], ['.', '.', '.', '.', '8', '.', '.', '7', '9']], False), ([['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.']], True), ([['1', '1', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.']], False), ([['1', '.', '.', '.', '.', '.', '.', '.', '.'], ['1', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.']], False), ([['1', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '1', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.']], False), ([['1', '2', '3', '4', '5', '6', '7', '8', '9'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.']], True), ([['1', '.', '.', '.', '.', '.', '.', '.', '.'], ['2', '.', '.', '.', '.', '.', '.', '.', '.'], ['3', '.', '.', '.', '.', '.', '.', '.', '.'], ['4', '.', '.', '.', '.', '.', '.', '.', '.'], ['5', '.', '.', '.', '.', '.', '.', '.', '.'], ['6', '.', '.', '.', '.', '.', '.', '.', '.'], ['7', '.', '.', '.', '.', '.', '.', '.', '.'], ['8', '.', '.', '.', '.', '.', '.', '.', '.'], ['9', '.', '.', '.', '.', '.', '.', '.', '.']], True), ([['1', '2', '3', '.', '.', '.', '.', '.', '.'], ['4', '5', '6', '.', '.', '.', '.', '.', '.'], ['7', '8', '9', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.']], True), ([['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '5', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '5', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.']], False), ([['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '7', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '7', '.']], False), ([['3', '3', '3', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.']], False), ([['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['9', '.', '.', '.', '.', '.', '.', '.', '9']], False), ([['.', '.', '.', '.', '.', '.', '.', '.', '4'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '4']], False), ([['1', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '2', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '3', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '4', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '5', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '6', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '7', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '8', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '9']], True), ([['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '1', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.']], True)]", + "test_cases": { + "list": [ + "([['5', '3', '.', '.', '7', '.', '.', '.', '.'], ['6', '.', '.', '1', '9', '5', '.', '.', '.'], ['.', '9', '8', '.', '.', '.', '.', '6', '.'], ['8', '.', '.', '.', '6', '.', '.', '.', '3'], ['4', '.', '.', '8', '.', '3', '.', '.', '1'], ['7', '.', '.', '.', '2', '.', '.', '.', '6'], ['.', '6', '.', '.', '.', '.', '2', '8', '.'], ['.', '.', '.', '4', '1', '9', '.', '.', '5'], ['.', '.', '.', '.', '8', '.', '.', '7', '9']], True)", + "([['8', '3', '.', '.', '7', '.', '.', '.', '.'], ['6', '.', '.', '1', '9', '5', '.', '.', '.'], ['.', '9', '8', '.', '.', '.', '.', '6', '.'], ['8', '.', '.', '.', '6', '.', '.', '.', '3'], ['4', '.', '.', '8', '.', '3', '.', '.', '1'], ['7', '.', '.', '.', '2', '.', '.', '.', '6'], ['.', '6', '.', '.', '.', '.', '2', '8', '.'], ['.', '.', '.', '4', '1', '9', '.', '.', '5'], ['.', '.', '.', '.', '8', '.', '.', '7', '9']], False)", + "([['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.']], True)", + "([['1', '1', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.']], False)", + "([['1', '.', '.', '.', '.', '.', '.', '.', '.'], ['1', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.']], False)", + "([['1', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '1', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.']], False)", + "([['1', '2', '3', '4', '5', '6', '7', '8', '9'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.']], True)", + "([['1', '.', '.', '.', '.', '.', '.', '.', '.'], ['2', '.', '.', '.', '.', '.', '.', '.', '.'], ['3', '.', '.', '.', '.', '.', '.', '.', '.'], ['4', '.', '.', '.', '.', '.', '.', '.', '.'], ['5', '.', '.', '.', '.', '.', '.', '.', '.'], ['6', '.', '.', '.', '.', '.', '.', '.', '.'], ['7', '.', '.', '.', '.', '.', '.', '.', '.'], ['8', '.', '.', '.', '.', '.', '.', '.', '.'], ['9', '.', '.', '.', '.', '.', '.', '.', '.']], True)", + "([['1', '2', '3', '.', '.', '.', '.', '.', '.'], ['4', '5', '6', '.', '.', '.', '.', '.', '.'], ['7', '8', '9', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.']], True)", + "([['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '5', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '5', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.']], False)", + "([['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '7', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '7', '.']], False)", + "([['3', '3', '3', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.']], False)", + "([['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['9', '.', '.', '.', '.', '.', '.', '.', '9']], False)", + "([['.', '.', '.', '.', '.', '.', '.', '.', '4'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '4']], False)", + "([['1', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '2', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '3', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '4', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '5', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '6', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '7', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '8', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '9']], True)", + "([['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '1', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.']], True)" + ] + }, "body": " result = run_is_valid_sudoku(Solution, board)\n assert_is_valid_sudoku(result, expected)" } ] }, - "playground_imports": "from helpers import run_is_valid_sudoku, assert_is_valid_sudoku\nfrom solution import Solution", "playground_setup": "# Example test case\nboard = [['5','3','.','.','7','.','.','.','.'],['6','.','.','1','9','5','.','.','.'],['.','9','8','.','.','.','.','6','.'],['8','.','.','.','6','.','.','.','3'],['4','.','.','8','.','3','.','.','1'],['7','.','.','.','2','.','.','.','6'],['.','6','.','.','.','.','2','8','.'],['.','.','.','4','1','9','.','.','5'],['.','.','.','.','.','.','.','7','9']]\nexpected = True", "playground_run": "result = run_is_valid_sudoku(Solution, board)\nresult", diff --git a/leetcode_py/cli/resources/leetcode/json/problems/validate_binary_search_tree.json b/leetcode_py/cli/resources/leetcode/json/problems/validate_binary_search_tree.json index 24095c4..adcdd2a 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/validate_binary_search_tree.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/validate_binary_search_tree.json @@ -5,7 +5,9 @@ "problem_title": "Validate Binary Search Tree", "difficulty": "Medium", "topics": "Tree, Depth-First Search, Binary Search Tree, Binary Tree", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "Given the `root` of a binary tree, determine if it is a valid binary search tree (BST).\n\nA **valid BST** is defined as follows:\n\n- The left subtree of a node contains only nodes with keys **strictly less than** the node's key.\n- The right subtree of a node contains only nodes with keys **strictly greater than** the node's key.\n- Both the left and right subtrees must also be binary search trees.", "_readme_examples": { "list": [ @@ -44,7 +46,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -52,7 +60,22 @@ "name": "test_is_valid_bst", "signature": "(self, root_list: list[int | None], expected: bool)", "parametrize": "root_list, expected", - "test_cases": "[([2, 1, 3], True), ([5, 1, 4, None, None, 3, 6], False), ([1], True), ([1, 1], False), ([10, 5, 15, None, None, 6, 20], False), ([2, 1, 3, None, None, None, 4], True), ([0], True), ([2147483647], True), ([-2147483648], True), ([5, 4, 6, None, None, 3, 7], False), ([10, 5, 15, None, None, 12, 20, None, None, None, None, 6, 25], True), ([3, 1, 5, 0, 2, 4, 6], True)]", + "test_cases": { + "list": [ + "([2, 1, 3], True)", + "([5, 1, 4, None, None, 3, 6], False)", + "([1], True)", + "([1, 1], False)", + "([10, 5, 15, None, None, 6, 20], False)", + "([2, 1, 3, None, None, None, 4], True)", + "([0], True)", + "([2147483647], True)", + "([-2147483648], True)", + "([5, 4, 6, None, None, 3, 7], False)", + "([10, 5, 15, None, None, 12, 20, None, None, None, None, 6, 25], True)", + "([3, 1, 5, 0, 2, 4, 6], True)" + ] + }, "body": " result = run_is_valid_bst(Solution, root_list)\n assert_is_valid_bst(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/word_break.json b/leetcode_py/cli/resources/leetcode/json/problems/word_break.json index 89d9d1b..9a27c5b 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/word_break.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/word_break.json @@ -5,7 +5,9 @@ "problem_title": "Word Break", "difficulty": "Medium", "topics": "Array, Hash Table, String, Dynamic Programming, Trie, Memoization", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "Given a string `s` and a dictionary of strings `wordDict`, return `true` if `s` can be segmented into a space-separated sequence of one or more dictionary words.\n\n**Note** that the same word in the dictionary may be reused multiple times in the segmentation.", "_readme_examples": { "list": [ @@ -47,7 +49,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -55,7 +63,25 @@ "name": "test_word_break", "signature": "(self, s: str, word_dict: list[str], expected: bool)", "parametrize": "s, word_dict, expected", - "test_cases": "[('leetcode', ['leet', 'code'], True), ('applepenapple', ['apple', 'pen'], True), ('catsandog', ['cats', 'dog', 'sand', 'and', 'cat'], False), ('', [], True), ('a', ['a'], True), ('ab', ['a', 'b'], True), ('abcd', ['a', 'abc', 'd'], True), ('aaaaaaa', ['aaaa', 'aaa'], True), ('aaaaaaa', ['aaaa', 'aa'], False), ('cars', ['car', 'ca', 'rs'], True), ('raceacar', ['race', 'a', 'car'], True), ('abcdef', ['abc', 'def'], True), ('abcdef', ['ab', 'cd', 'ef'], True), ('goalspecial', ['go', 'goal', 'goals', 'special'], True), ('bb', ['a', 'b', 'bbb', 'bbbb'], True)]", + "test_cases": { + "list": [ + "('leetcode', ['leet', 'code'], True)", + "('applepenapple', ['apple', 'pen'], True)", + "('catsandog', ['cats', 'dog', 'sand', 'and', 'cat'], False)", + "('', [], True)", + "('a', ['a'], True)", + "('ab', ['a', 'b'], True)", + "('abcd', ['a', 'abc', 'd'], True)", + "('aaaaaaa', ['aaaa', 'aaa'], True)", + "('aaaaaaa', ['aaaa', 'aa'], False)", + "('cars', ['car', 'ca', 'rs'], True)", + "('raceacar', ['race', 'a', 'car'], True)", + "('abcdef', ['abc', 'def'], True)", + "('abcdef', ['ab', 'cd', 'ef'], True)", + "('goalspecial', ['go', 'goal', 'goals', 'special'], True)", + "('bb', ['a', 'b', 'bbb', 'bbbb'], True)" + ] + }, "body": " result = run_word_break(Solution, s, word_dict)\n assert_word_break(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/word_ladder.json b/leetcode_py/cli/resources/leetcode/json/problems/word_ladder.json index 102223a..4912d8f 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/word_ladder.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/word_ladder.json @@ -5,7 +5,9 @@ "problem_title": "Word Ladder", "difficulty": "Hard", "topics": "Hash Table, String, Breadth-First Search", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "A **transformation sequence** from word `beginWord` to word `endWord` using a dictionary `wordList` is a sequence of words `beginWord -> s1 -> s2 -> ... -> sk` such that:\n\n- Every adjacent pair of words differs by a single letter.\n- Every `si` for `1 <= i <= k` is in `wordList`. Note that `beginWord` does not need to be in `wordList`.\n- `sk == endWord`\n\nGiven two words, `beginWord` and `endWord`, and a dictionary `wordList`, return the **number of words** in the **shortest transformation sequence** from `beginWord` to `endWord`, or `0` if no such sequence exists.", "_readme_examples": { "list": [ @@ -44,7 +46,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -52,7 +60,25 @@ "name": "test_ladder_length", "signature": "(self, begin_word: str, end_word: str, word_list: list[str], expected: int)", "parametrize": "begin_word, end_word, word_list, expected", - "test_cases": "[(\"hit\", \"cog\", [\"hot\", \"dot\", \"dog\", \"lot\", \"log\", \"cog\"], 5), (\"hit\", \"cog\", [\"hot\", \"dot\", \"dog\", \"lot\", \"log\"], 0), (\"a\", \"c\", [\"a\", \"b\", \"c\"], 2), (\"hot\", \"dog\", [\"hot\", \"dog\"], 0), (\"hot\", \"dog\", [\"hot\", \"hog\", \"dog\"], 3), (\"red\", \"tax\", [\"ted\", \"tex\", \"red\", \"tax\", \"tad\", \"den\", \"rex\", \"pee\"], 4), (\"talk\", \"tail\", [\"talk\", \"tons\", \"fall\", \"tail\", \"gale\", \"hall\", \"negs\"], 0), (\"qa\", \"sq\", [\"si\", \"go\", \"se\", \"cm\", \"so\", \"ph\", \"mt\", \"db\", \"mb\", \"sb\", \"kr\", \"ln\", \"tm\", \"le\", \"av\", \"sm\", \"ar\", \"ci\", \"ca\", \"br\", \"ti\", \"ba\", \"to\", \"ra\", \"fa\", \"yo\", \"ow\", \"sn\", \"ya\", \"cr\", \"po\", \"fe\", \"ho\", \"ma\", \"re\", \"or\", \"rn\", \"au\", \"ur\", \"rh\", \"sr\", \"tc\", \"lt\", \"lo\", \"as\", \"fr\", \"nb\", \"yb\", \"if\", \"pb\", \"ge\", \"th\", \"pm\", \"rb\", \"sh\", \"co\", \"ga\", \"li\", \"ha\", \"hz\", \"no\", \"bi\", \"di\", \"hi\", \"qa\", \"pi\", \"os\", \"uh\", \"wm\", \"an\", \"me\", \"mo\", \"na\", \"la\", \"st\", \"er\", \"sc\", \"ne\", \"mn\", \"mi\", \"am\", \"ex\", \"pt\", \"io\", \"be\", \"fm\", \"ta\", \"tb\", \"ni\", \"mr\", \"pa\", \"he\", \"lr\", \"sq\", \"ye\"], 5), (\"cet\", \"ism\", [\"kid\", \"tag\", \"pup\", \"ail\", \"tun\", \"woo\"], 0), (\"lost\", \"miss\", [\"most\", \"mist\", \"miss\", \"lost\", \"fist\", \"fish\"], 4), (\"cat\", \"dog\", [\"bat\", \"bag\", \"dag\", \"dog\", \"cat\"], 5), (\"game\", \"thee\", [\"frye\", \"heat\", \"tree\", \"thee\", \"game\", \"free\"], 0), (\"teach\", \"place\", [\"peale\", \"wilts\", \"place\", \"fetch\"], 0), (\"sail\", \"boat\", [\"bail\", \"foil\", \"coat\", \"boat\", \"sail\"], 0), (\"cold\", \"warm\", [\"cold\", \"cord\", \"word\", \"ward\", \"warm\"], 5)]", + "test_cases": { + "list": [ + "(\"hit\", \"cog\", [\"hot\", \"dot\", \"dog\", \"lot\", \"log\", \"cog\"], 5)", + "(\"hit\", \"cog\", [\"hot\", \"dot\", \"dog\", \"lot\", \"log\"], 0)", + "(\"a\", \"c\", [\"a\", \"b\", \"c\"], 2)", + "(\"hot\", \"dog\", [\"hot\", \"dog\"], 0)", + "(\"hot\", \"dog\", [\"hot\", \"hog\", \"dog\"], 3)", + "(\"red\", \"tax\", [\"ted\", \"tex\", \"red\", \"tax\", \"tad\", \"den\", \"rex\", \"pee\"], 4)", + "(\"talk\", \"tail\", [\"talk\", \"tons\", \"fall\", \"tail\", \"gale\", \"hall\", \"negs\"], 0)", + "(\"qa\", \"sq\", [\"si\", \"go\", \"se\", \"cm\", \"so\", \"ph\", \"mt\", \"db\", \"mb\", \"sb\", \"kr\", \"ln\", \"tm\", \"le\", \"av\", \"sm\", \"ar\", \"ci\", \"ca\", \"br\", \"ti\", \"ba\", \"to\", \"ra\", \"fa\", \"yo\", \"ow\", \"sn\", \"ya\", \"cr\", \"po\", \"fe\", \"ho\", \"ma\", \"re\", \"or\", \"rn\", \"au\", \"ur\", \"rh\", \"sr\", \"tc\", \"lt\", \"lo\", \"as\", \"fr\", \"nb\", \"yb\", \"if\", \"pb\", \"ge\", \"th\", \"pm\", \"rb\", \"sh\", \"co\", \"ga\", \"li\", \"ha\", \"hz\", \"no\", \"bi\", \"di\", \"hi\", \"qa\", \"pi\", \"os\", \"uh\", \"wm\", \"an\", \"me\", \"mo\", \"na\", \"la\", \"st\", \"er\", \"sc\", \"ne\", \"mn\", \"mi\", \"am\", \"ex\", \"pt\", \"io\", \"be\", \"fm\", \"ta\", \"tb\", \"ni\", \"mr\", \"pa\", \"he\", \"lr\", \"sq\", \"ye\"], 5)", + "(\"cet\", \"ism\", [\"kid\", \"tag\", \"pup\", \"ail\", \"tun\", \"woo\"], 0)", + "(\"lost\", \"miss\", [\"most\", \"mist\", \"miss\", \"lost\", \"fist\", \"fish\"], 4)", + "(\"cat\", \"dog\", [\"bat\", \"bag\", \"dag\", \"dog\", \"cat\"], 5)", + "(\"game\", \"thee\", [\"frye\", \"heat\", \"tree\", \"thee\", \"game\", \"free\"], 0)", + "(\"teach\", \"place\", [\"peale\", \"wilts\", \"place\", \"fetch\"], 0)", + "(\"sail\", \"boat\", [\"bail\", \"foil\", \"coat\", \"boat\", \"sail\"], 0)", + "(\"cold\", \"warm\", [\"cold\", \"cord\", \"word\", \"ward\", \"warm\"], 5)" + ] + }, "body": " result = run_ladder_length(Solution, begin_word, end_word, word_list)\n assert_ladder_length(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/word_search.json b/leetcode_py/cli/resources/leetcode/json/problems/word_search.json index ea30fc4..2878c43 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/word_search.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/word_search.json @@ -5,7 +5,9 @@ "problem_title": "Word Search", "difficulty": "Medium", "topics": "Array, String, Backtracking, Depth-First Search, Matrix", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "Given an `m x n` grid of characters `board` and a string `word`, return `true` *if* `word` *exists in the grid*.\n\nThe word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically neighboring. The same letter cell may not be used more than once.", "_readme_examples": { "list": [ @@ -47,7 +49,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -55,7 +63,22 @@ "name": "test_exist", "signature": "(self, board: list[list[str]], word: str, expected: bool)", "parametrize": "board, word, expected", - "test_cases": "[([['A', 'B', 'C', 'E'], ['S', 'F', 'C', 'S'], ['A', 'D', 'E', 'E']], 'ABCCED', True), ([['A', 'B', 'C', 'E'], ['S', 'F', 'C', 'S'], ['A', 'D', 'E', 'E']], 'SEE', True), ([['A', 'B', 'C', 'E'], ['S', 'F', 'C', 'S'], ['A', 'D', 'E', 'E']], 'ABCB', False), ([['A']], 'A', True), ([['A']], 'B', False), ([['A', 'B'], ['C', 'D']], 'ACDB', True), ([['A', 'B'], ['C', 'D']], 'ABDC', True), ([['A', 'B'], ['C', 'D']], 'ABCD', False), ([['C', 'A', 'A'], ['A', 'A', 'A'], ['B', 'C', 'D']], 'AAB', True), ([['A', 'B', 'C', 'E'], ['S', 'F', 'C', 'S'], ['A', 'D', 'E', 'E']], 'ABCESEEEFS', False), ([['A', 'A', 'A', 'A', 'A', 'A'], ['A', 'A', 'A', 'A', 'A', 'A'], ['A', 'A', 'A', 'A', 'A', 'A'], ['A', 'A', 'A', 'A', 'A', 'A'], ['A', 'A', 'A', 'A', 'A', 'A'], ['A', 'A', 'A', 'A', 'A', 'A']], 'AAAAAAAAAAAAAAB', False), ([['A', 'B', 'C', 'E'], ['S', 'F', 'C', 'S'], ['A', 'D', 'E', 'E']], 'SFCS', True)]", + "test_cases": { + "list": [ + "([['A', 'B', 'C', 'E'], ['S', 'F', 'C', 'S'], ['A', 'D', 'E', 'E']], 'ABCCED', True)", + "([['A', 'B', 'C', 'E'], ['S', 'F', 'C', 'S'], ['A', 'D', 'E', 'E']], 'SEE', True)", + "([['A', 'B', 'C', 'E'], ['S', 'F', 'C', 'S'], ['A', 'D', 'E', 'E']], 'ABCB', False)", + "([['A']], 'A', True)", + "([['A']], 'B', False)", + "([['A', 'B'], ['C', 'D']], 'ACDB', True)", + "([['A', 'B'], ['C', 'D']], 'ABDC', True)", + "([['A', 'B'], ['C', 'D']], 'ABCD', False)", + "([['C', 'A', 'A'], ['A', 'A', 'A'], ['B', 'C', 'D']], 'AAB', True)", + "([['A', 'B', 'C', 'E'], ['S', 'F', 'C', 'S'], ['A', 'D', 'E', 'E']], 'ABCESEEEFS', False)", + "([['A', 'A', 'A', 'A', 'A', 'A'], ['A', 'A', 'A', 'A', 'A', 'A'], ['A', 'A', 'A', 'A', 'A', 'A'], ['A', 'A', 'A', 'A', 'A', 'A'], ['A', 'A', 'A', 'A', 'A', 'A'], ['A', 'A', 'A', 'A', 'A', 'A']], 'AAAAAAAAAAAAAAB', False)", + "([['A', 'B', 'C', 'E'], ['S', 'F', 'C', 'S'], ['A', 'D', 'E', 'E']], 'SFCS', True)" + ] + }, "body": " result = run_exist(Solution, board, word)\n assert_exist(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/json/problems/zero_one_matrix.json b/leetcode_py/cli/resources/leetcode/json/problems/zero_one_matrix.json index 21aca93..f9ace61 100644 --- a/leetcode_py/cli/resources/leetcode/json/problems/zero_one_matrix.json +++ b/leetcode_py/cli/resources/leetcode/json/problems/zero_one_matrix.json @@ -5,7 +5,9 @@ "problem_title": "01 Matrix", "difficulty": "Medium", "topics": "Array, Dynamic Programming, Breadth-First Search, Matrix", - "_tags": { "list": ["grind-75"] }, + "_tags": { + "list": ["grind-75"] + }, "readme_description": "Given an `m x n` binary matrix `mat`, return the distance of the nearest `0` for each cell.\n\nThe distance between two cells sharing a common edge is `1`.", "_readme_examples": { "list": [ @@ -44,7 +46,13 @@ ] }, "_test_helper_methods": { - "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] + "list": [ + { + "name": "setup_method", + "parameters": "", + "body": "self.solution = Solution()" + } + ] }, "_test_methods": { "list": [ @@ -52,7 +60,23 @@ "name": "test_update_matrix", "signature": "(self, mat: list[list[int]], expected: list[list[int]])", "parametrize": "mat, expected", - "test_cases": "[([[0, 0, 0], [0, 1, 0], [0, 0, 0]], [[0, 0, 0], [0, 1, 0], [0, 0, 0]]), ([[0, 0, 0], [0, 1, 0], [1, 1, 1]], [[0, 0, 0], [0, 1, 0], [1, 2, 1]]), ([[0]], [[0]]), ([[1, 0]], [[1, 0]]), ([[1, 1], [1, 0]], [[2, 1], [1, 0]]), ([[0, 1, 0], [1, 1, 1], [0, 1, 0]], [[0, 1, 0], [1, 2, 1], [0, 1, 0]]), ([[1, 0, 1], [1, 1, 1], [1, 1, 1]], [[1, 0, 1], [2, 1, 2], [3, 2, 3]]), ([[0, 1, 0, 0], [1, 1, 1, 0], [1, 1, 1, 0]], [[0, 1, 0, 0], [1, 2, 1, 0], [2, 2, 1, 0]]), ([[1, 1, 1], [1, 1, 1], [1, 1, 0]], [[4, 3, 2], [3, 2, 1], [2, 1, 0]]), ([[0, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]], [[0, 1, 2, 3], [1, 2, 3, 4], [2, 3, 4, 5]]), ([[1, 0, 0], [1, 1, 0], [1, 1, 1]], [[1, 0, 0], [2, 1, 0], [3, 2, 1]]), ([[0, 0, 1], [0, 1, 1], [1, 1, 1]], [[0, 0, 1], [0, 1, 2], [1, 2, 3]]), ([[1, 1, 0, 1], [1, 0, 1, 1], [0, 1, 1, 1]], [[2, 1, 0, 1], [1, 0, 1, 2], [0, 1, 2, 3]])]", + "test_cases": { + "list": [ + "([[0, 0, 0], [0, 1, 0], [0, 0, 0]], [[0, 0, 0], [0, 1, 0], [0, 0, 0]])", + "([[0, 0, 0], [0, 1, 0], [1, 1, 1]], [[0, 0, 0], [0, 1, 0], [1, 2, 1]])", + "([[0]], [[0]])", + "([[1, 0]], [[1, 0]])", + "([[1, 1], [1, 0]], [[2, 1], [1, 0]])", + "([[0, 1, 0], [1, 1, 1], [0, 1, 0]], [[0, 1, 0], [1, 2, 1], [0, 1, 0]])", + "([[1, 0, 1], [1, 1, 1], [1, 1, 1]], [[1, 0, 1], [2, 1, 2], [3, 2, 3]])", + "([[0, 1, 0, 0], [1, 1, 1, 0], [1, 1, 1, 0]], [[0, 1, 0, 0], [1, 2, 1, 0], [2, 2, 1, 0]])", + "([[1, 1, 1], [1, 1, 1], [1, 1, 0]], [[4, 3, 2], [3, 2, 1], [2, 1, 0]])", + "([[0, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]], [[0, 1, 2, 3], [1, 2, 3, 4], [2, 3, 4, 5]])", + "([[1, 0, 0], [1, 1, 0], [1, 1, 1]], [[1, 0, 0], [2, 1, 0], [3, 2, 1]])", + "([[0, 0, 1], [0, 1, 1], [1, 1, 1]], [[0, 0, 1], [0, 1, 2], [1, 2, 3]])", + "([[1, 1, 0, 1], [1, 0, 1, 1], [0, 1, 1, 1]], [[2, 1, 0, 1], [1, 0, 1, 2], [0, 1, 2, 3]])" + ] + }, "body": " result = run_update_matrix(Solution, mat)\n assert_update_matrix(result, expected)" } ] diff --git a/leetcode_py/cli/resources/leetcode/{{cookiecutter.problem_name}}/test_solution.py b/leetcode_py/cli/resources/leetcode/{{cookiecutter.problem_name}}/test_solution.py index 11fc019..1949763 100644 --- a/leetcode_py/cli/resources/leetcode/{{cookiecutter.problem_name}}/test_solution.py +++ b/leetcode_py/cli/resources/leetcode/{{cookiecutter.problem_name}}/test_solution.py @@ -27,7 +27,7 @@ class Test{{cookiecutter.test_class_name}}: @logged_test {% endif %} {% if method.parametrize %} - @pytest.mark.parametrize("{{method.parametrize}}", {{method.test_cases}}) + @pytest.mark.parametrize("{{method.parametrize}}", [{{method.test_cases.list | join(', ')}}]) {% endif %} def {{method.name}}{{method.signature}}: {{method.body}} diff --git a/leetcode_py/tools/check_test_cases.py b/leetcode_py/tools/check_test_cases.py index c24c6a9..46be07b 100644 --- a/leetcode_py/tools/check_test_cases.py +++ b/leetcode_py/tools/check_test_cases.py @@ -1,6 +1,5 @@ #!/usr/bin/env python3 -import ast import json from typing import Any @@ -20,22 +19,9 @@ def count_test_cases_for_problem(json_data: dict[str, Any]) -> int: for method in test_methods: test_cases = method.get("test_cases", "") - if test_cases.strip(): - try: - # Try ast.literal_eval first (safer) - cases_list = ast.literal_eval(test_cases) - total += len(cases_list) - except (ValueError, SyntaxError): - try: - # Fallback to eval for expressions like 'string' * 100 - # This is safe since we're only evaluating test case data - cases_list = eval(test_cases) - total += len(cases_list) - except Exception as e: - # Re-raise with more context - raise ValueError( - f"Failed to parse test_cases in method '{method.get('name', 'unknown')}': {e}" - ) + + if isinstance(test_cases, dict) and "list" in test_cases: + total += len(test_cases["list"]) return total From 907a6406f4debb2f6452976d154203a5487fa6f7 Mon Sep 17 00:00:00 2001 From: Wisaroot Lertthaweedech Date: Sat, 4 Oct 2025 11:05:39 +0700 Subject: [PATCH 3/3] fix: update test check_test_cases to reflect new implementation --- tests/tools/test_check_test_cases.py | 43 +++++++++++++++++++++------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/tests/tools/test_check_test_cases.py b/tests/tools/test_check_test_cases.py index a9a53f0..b4ed5cc 100644 --- a/tests/tools/test_check_test_cases.py +++ b/tests/tools/test_check_test_cases.py @@ -9,27 +9,45 @@ class TestCountTestCasesForProblem: "json_data, expected", [ ( - {"test_methods": [{"test_cases": "[(1, 2, 3), (4, 5, 6)]"}, {"test_cases": "[(7, 8)]"}]}, + { + "test_methods": [ + {"test_cases": {"list": ["(1, 2, 3)", "(4, 5, 6)"]}}, + {"test_cases": {"list": ["(7, 8)"]}}, + ] + }, 3, ), ( { "_test_methods": { "list": [ - {"test_cases": "[(1, 2), (3, 4), (5, 6)]"}, - {"test_cases": "[(7, 8, 9)]"}, + {"test_cases": {"list": ["(1, 2)", "(3, 4)", "(5, 6)"]}}, + {"test_cases": {"list": ["(7, 8, 9)"]}}, ] } }, 4, ), - ({"test_methods": [{"test_cases": "[]"}, {"test_cases": ""}, {"test_cases": " "}]}, 0), + ( + { + "test_methods": [ + {"test_cases": {"list": []}}, + {"test_cases": ""}, + {"test_cases": " "}, + ] + }, + 0, + ), ({}, 0), ( { "test_methods": [ - {"test_cases": "[([1, 2], 'hello', True), ([3, 4], 'world', False)]"}, - {"test_cases": "[([], '', None)]"}, + { + "test_cases": { + "list": ["([1, 2], 'hello', True)", "([3, 4], 'world', False)"] + } + }, + {"test_cases": {"list": ["([], '', None)"]}}, ] }, 3, @@ -39,16 +57,21 @@ class TestCountTestCasesForProblem: def test_count_test_cases(self, json_data, expected): assert count_test_cases_for_problem(json_data) == expected - def test_invalid_test_cases_raises_error(self): + def test_invalid_test_cases_returns_zero(self): + """Test that invalid test cases are ignored and return 0.""" json_data = {"test_methods": [{"test_cases": "invalid python literal"}]} - with pytest.raises((ValueError, SyntaxError)): - count_test_cases_for_problem(json_data) + # Current implementation ignores invalid test cases and returns 0 + assert count_test_cases_for_problem(json_data) == 0 def test_python_expressions_in_test_cases(self): """Test that Python expressions like 'string' * 100 are handled correctly.""" json_data = { "test_methods": [ - {"test_cases": "[('input', 'expected'), ('100[leetcode]', 'leetcode' * 100)]"} + { + "test_cases": { + "list": ["('input', 'expected')", "('100[leetcode]', 'leetcode' * 100)"] + } + } ] } # Should not raise an error and should count 2 test cases