diff --git a/README.md b/README.md index 900029d..bd9cb0b 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,21 @@ # LeetCode Practice Environment Generator 🚀 +# READ THIS FIRST +# SETUP + +🧱 Step 2: Create a virtual environment + + +This keeps your dependencies clean and isolated. + +```bash +python3 -m venv leetcode-env +``` +Activate it: +```bash +source leetcode-env/bin/activate +``` + [![tests](https://img.shields.io/github/actions/workflow/status/wisarootl/leetcode-py/ci-test.yml?branch=main&label=tests&logo=github)](https://github.com/wisarootl/leetcode-py/actions/workflows/ci-test.yml) [![release](https://img.shields.io/github/actions/workflow/status/wisarootl/leetcode-py/cd.yml?branch=main&label=release&logo=github)](https://github.com/wisarootl/leetcode-py/actions/workflows/cd.yml) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=wisarootl_leetcode-py&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=wisarootl_leetcode-py) diff --git a/leetcode/accounts_merge/playground.ipynb b/leetcode/accounts_merge/playground.ipynb new file mode 100644 index 0000000..089603f --- /dev/null +++ b/leetcode/accounts_merge/playground.ipynb @@ -0,0 +1,66 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "be09b1da", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_accounts_merge, run_accounts_merge\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0ce59fad", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "accounts = [\n", + " [\"John\", \"johnsmith@mail.com\", \"john_newyork@mail.com\"],\n", + " [\"John\", \"johnsmith@mail.com\", \"john00@mail.com\"],\n", + " [\"Mary\", \"mary@mail.com\"],\n", + " [\"John\", \"johnnybravo@mail.com\"],\n", + "]\n", + "expected = [\n", + " [\"John\", \"john00@mail.com\", \"john_newyork@mail.com\", \"johnsmith@mail.com\"],\n", + " [\"Mary\", \"mary@mail.com\"],\n", + " [\"John\", \"johnnybravo@mail.com\"],\n", + "]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9d78522a", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_accounts_merge(Solution, accounts)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0767b21b", + "metadata": {}, + "outputs": [], + "source": [ + "assert_accounts_merge(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/add_binary/playground.ipynb b/leetcode/add_binary/playground.ipynb new file mode 100644 index 0000000..0059282 --- /dev/null +++ b/leetcode/add_binary/playground.ipynb @@ -0,0 +1,58 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "8678b01c", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_add_binary, run_add_binary\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e9fd7e3c", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "a = \"11\"\n", + "b = \"1\"\n", + "expected = \"100\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "56368441", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_add_binary(Solution, a, b)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "11a1ee58", + "metadata": {}, + "outputs": [], + "source": [ + "assert_add_binary(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/add_two_numbers/playground.ipynb b/leetcode/add_two_numbers/playground.ipynb new file mode 100644 index 0000000..4da6d2d --- /dev/null +++ b/leetcode/add_two_numbers/playground.ipynb @@ -0,0 +1,58 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "e9abb12e", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_add_two_numbers, run_add_two_numbers\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "93e79c47", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "l1_vals = [2, 4, 3]\n", + "l2_vals = [5, 6, 4]\n", + "expected_vals = [7, 0, 8]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "affd559b", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_add_two_numbers(Solution, l1_vals, l2_vals)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7cbc5acf", + "metadata": {}, + "outputs": [], + "source": [ + "assert_add_two_numbers(result, expected_vals)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/alien_dictionary/playground.ipynb b/leetcode/alien_dictionary/playground.ipynb new file mode 100644 index 0000000..001f385 --- /dev/null +++ b/leetcode/alien_dictionary/playground.ipynb @@ -0,0 +1,57 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "0ba5e840", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_alien_order, run_alien_order\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0f00394c", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "words = [\"wrt\", \"wrf\", \"er\", \"ett\", \"rftt\"]\n", + "expected = \"wertf\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4ecab642", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_alien_order(Solution, words)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d3869abd", + "metadata": {}, + "outputs": [], + "source": [ + "assert_alien_order(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/balanced_binary_tree/playground.ipynb b/leetcode/balanced_binary_tree/playground.ipynb new file mode 100644 index 0000000..da2037c --- /dev/null +++ b/leetcode/balanced_binary_tree/playground.ipynb @@ -0,0 +1,70 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "01316af7", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_is_balanced, run_is_balanced\n", + "from solution import Solution\n", + "\n", + "from leetcode_py import TreeNode" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "dfcc4bfd", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "root_list: list[int | None] = [3, 9, 20, None, None, 15, 7]\n", + "expected = True" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f504f639", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_is_balanced(Solution, root_list)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6648a660", + "metadata": {}, + "outputs": [], + "source": [ + "root = TreeNode.from_list(root_list)\n", + "root" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8a3972a2", + "metadata": {}, + "outputs": [], + "source": [ + "assert_is_balanced(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/basic_calculator/playground.ipynb b/leetcode/basic_calculator/playground.ipynb new file mode 100644 index 0000000..c61304d --- /dev/null +++ b/leetcode/basic_calculator/playground.ipynb @@ -0,0 +1,60 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "e16d11b3", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_calculate, run_calculate\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5ecc025e", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "s = \"(1+(4+5+2)-3)+(6+8)\"\n", + "expected = 23" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c0b03d19", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_calculate(Solution, s)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "de6f6749", + "metadata": {}, + "outputs": [], + "source": [ + "assert_calculate(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/best_time_to_buy_and_sell_stock/playground.ipynb b/leetcode/best_time_to_buy_and_sell_stock/playground.ipynb new file mode 100644 index 0000000..be94e39 --- /dev/null +++ b/leetcode/best_time_to_buy_and_sell_stock/playground.ipynb @@ -0,0 +1,60 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "171a9642", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_max_profit, run_max_profit\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "389f70d2", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "prices = [7, 1, 5, 3, 6, 4]\n", + "expected = 5" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "dd5932ea", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_max_profit(Solution, prices)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "98c2e703", + "metadata": {}, + "outputs": [], + "source": [ + "assert_max_profit(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/binary_search/playground.ipynb b/leetcode/binary_search/playground.ipynb new file mode 100644 index 0000000..b4bb56b --- /dev/null +++ b/leetcode/binary_search/playground.ipynb @@ -0,0 +1,61 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "5b117916", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_search, run_search\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ec59f05d", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "nums = [-1, 0, 3, 5, 9, 12]\n", + "target = 9\n", + "expected = 4" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d123b65f", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_search(Solution, nums, target)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "37818558", + "metadata": {}, + "outputs": [], + "source": [ + "assert_search(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/binary_tree_level_order_traversal/playground.ipynb b/leetcode/binary_tree_level_order_traversal/playground.ipynb new file mode 100644 index 0000000..cb4e5df --- /dev/null +++ b/leetcode/binary_tree_level_order_traversal/playground.ipynb @@ -0,0 +1,60 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "aef4b60e", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_level_order, run_level_order\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f49ed4dd", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "root_list: list[int | None] = [3, 9, 20, None, None, 15, 7]\n", + "expected = [[3], [9, 20], [15, 7]]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9f75fbf7", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_level_order(Solution, root_list)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b837dfa2", + "metadata": {}, + "outputs": [], + "source": [ + "assert_level_order(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/binary_tree_maximum_path_sum/playground.ipynb b/leetcode/binary_tree_maximum_path_sum/playground.ipynb new file mode 100644 index 0000000..fab5e1d --- /dev/null +++ b/leetcode/binary_tree_maximum_path_sum/playground.ipynb @@ -0,0 +1,57 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "9129cf4e", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_max_path_sum, run_max_path_sum\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7ff08b57", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "root_list: list[int | None] = [1, 2, 3]\n", + "expected: int = 6" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a8c218dd", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_max_path_sum(Solution, root_list)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3aca010f", + "metadata": {}, + "outputs": [], + "source": [ + "assert_max_path_sum(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/binary_tree_right_side_view/playground.ipynb b/leetcode/binary_tree_right_side_view/playground.ipynb new file mode 100644 index 0000000..bf8a005 --- /dev/null +++ b/leetcode/binary_tree_right_side_view/playground.ipynb @@ -0,0 +1,73 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "16e0f82d", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_right_side_view, run_right_side_view\n", + "from solution import Solution\n", + "\n", + "from leetcode_py import TreeNode" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c4aec824", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "root_list: list[int | None] = [1, 2, 3, None, 5, None, 4]\n", + "expected = [1, 3, 4]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "168a7c6d", + "metadata": {}, + "outputs": [], + "source": [ + "root = TreeNode.from_list(root_list)\n", + "root" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ece3d283", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_right_side_view(Solution, root_list)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "99051ee1", + "metadata": {}, + "outputs": [], + "source": [ + "assert_right_side_view(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/climbing_stairs/playground.ipynb b/leetcode/climbing_stairs/playground.ipynb new file mode 100644 index 0000000..eb8b139 --- /dev/null +++ b/leetcode/climbing_stairs/playground.ipynb @@ -0,0 +1,60 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "c9fd3420", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_climb_stairs, run_climb_stairs\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3ecfd5f6", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "n = 3\n", + "expected = 3" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "89c198b4", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_climb_stairs(Solution, n)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ee647837", + "metadata": {}, + "outputs": [], + "source": [ + "assert_climb_stairs(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/clone_graph/playground.ipynb b/leetcode/clone_graph/playground.ipynb new file mode 100644 index 0000000..c835a57 --- /dev/null +++ b/leetcode/clone_graph/playground.ipynb @@ -0,0 +1,59 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "6b50c6ae", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_clone_graph, run_clone_graph\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "05635430", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "adj_list = [[2, 4], [1, 3], [2, 4], [1, 3]]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ba56fab4", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_clone_graph(Solution, adj_list)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b434d217", + "metadata": {}, + "outputs": [], + "source": [ + "assert_clone_graph(result, adj_list)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/coin_change/playground.ipynb b/leetcode/coin_change/playground.ipynb new file mode 100644 index 0000000..f4c84c7 --- /dev/null +++ b/leetcode/coin_change/playground.ipynb @@ -0,0 +1,61 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "338ff2b6", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_coin_change, run_coin_change\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c5fc7072", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "coins = [1, 2, 5]\n", + "amount = 11\n", + "expected = 3" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c8abd3fc", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_coin_change(Solution, coins, amount)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "713d63f2", + "metadata": {}, + "outputs": [], + "source": [ + "assert_coin_change(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/combination_sum/playground.ipynb b/leetcode/combination_sum/playground.ipynb new file mode 100644 index 0000000..fbc3092 --- /dev/null +++ b/leetcode/combination_sum/playground.ipynb @@ -0,0 +1,61 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "eeaae760", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_combination_sum, run_combination_sum\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4409ddc7", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "candidates = [2, 3, 6, 7]\n", + "target = 7\n", + "expected = [[2, 2, 3], [7]]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ade42ac4", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_combination_sum(Solution, candidates, target)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0ba37f67", + "metadata": {}, + "outputs": [], + "source": [ + "assert_combination_sum(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/construct_binary_tree_from_preorder_and_inorder_traversal/playground.ipynb b/leetcode/construct_binary_tree_from_preorder_and_inorder_traversal/playground.ipynb new file mode 100644 index 0000000..dd47b9b --- /dev/null +++ b/leetcode/construct_binary_tree_from_preorder_and_inorder_traversal/playground.ipynb @@ -0,0 +1,58 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "e3402e01", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_build_tree, run_build_tree\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2f260f73", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "preorder = [3, 9, 20, 15, 7]\n", + "inorder = [9, 3, 15, 20, 7]\n", + "expected_list = [3, 9, 20, None, None, 15, 7]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9f7c9a84", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_build_tree(Solution, preorder, inorder)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cac9c00c", + "metadata": {}, + "outputs": [], + "source": [ + "assert_build_tree(result, expected_list)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/container_with_most_water/playground.ipynb b/leetcode/container_with_most_water/playground.ipynb new file mode 100644 index 0000000..8f7e7bb --- /dev/null +++ b/leetcode/container_with_most_water/playground.ipynb @@ -0,0 +1,60 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "53c1aa31", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_max_area, run_max_area\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b9031024", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "height = [1, 8, 6, 2, 5, 4, 8, 3, 7]\n", + "expected = 49" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "95264d99", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_max_area(Solution, height)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "de24b536", + "metadata": {}, + "outputs": [], + "source": [ + "assert_max_area(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/contains_duplicate/playground.ipynb b/leetcode/contains_duplicate/playground.ipynb new file mode 100644 index 0000000..797e4ff --- /dev/null +++ b/leetcode/contains_duplicate/playground.ipynb @@ -0,0 +1,60 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "6324699d", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_contains_duplicate, run_contains_duplicate\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "55305944", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "nums = [1, 2, 3, 1]\n", + "expected = True" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "72d1a78e", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_contains_duplicate(Solution, nums)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "51044fe8", + "metadata": {}, + "outputs": [], + "source": [ + "assert_contains_duplicate(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/contiguous_array/playground.ipynb b/leetcode/contiguous_array/playground.ipynb new file mode 100644 index 0000000..f21603e --- /dev/null +++ b/leetcode/contiguous_array/playground.ipynb @@ -0,0 +1,57 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "dca604bc", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_find_max_length, run_find_max_length\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7fdabccb", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "nums = [0, 1]\n", + "expected = 2" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ed8757e0", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_find_max_length(Solution, nums)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "726c8a50", + "metadata": {}, + "outputs": [], + "source": [ + "assert_find_max_length(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/counting_bits/playground.ipynb b/leetcode/counting_bits/playground.ipynb new file mode 100644 index 0000000..bb99171 --- /dev/null +++ b/leetcode/counting_bits/playground.ipynb @@ -0,0 +1,57 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "01a31510", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_count_bits, run_count_bits\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6c075a71", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "n = 2\n", + "expected = [0, 1, 1]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "19cbf988", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_count_bits(Solution, n)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "90bb4f07", + "metadata": {}, + "outputs": [], + "source": [ + "assert_count_bits(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/course_schedule/playground.ipynb b/leetcode/course_schedule/playground.ipynb new file mode 100644 index 0000000..797622a --- /dev/null +++ b/leetcode/course_schedule/playground.ipynb @@ -0,0 +1,61 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "69199d15", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_can_finish, run_can_finish\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "661d36af", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "num_courses = 2\n", + "prerequisites = [[1, 0]]\n", + "expected = True" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ac4c6e02", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_can_finish(Solution, num_courses, prerequisites)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "486e2391", + "metadata": {}, + "outputs": [], + "source": [ + "assert_can_finish(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/course_schedule_ii/playground.ipynb b/leetcode/course_schedule_ii/playground.ipynb new file mode 100644 index 0000000..140e17f --- /dev/null +++ b/leetcode/course_schedule_ii/playground.ipynb @@ -0,0 +1,58 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "57361907", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_find_order, run_find_order\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "42316f53", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "num_courses = 4\n", + "prerequisites = [[1, 0], [2, 0], [3, 1], [3, 2]]\n", + "expected = [0, 2, 1, 3]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4d463b39", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_find_order(Solution, num_courses, prerequisites)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "23a85c56", + "metadata": {}, + "outputs": [], + "source": [ + "assert_find_order(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/daily_temperatures/playground.ipynb b/leetcode/daily_temperatures/playground.ipynb new file mode 100644 index 0000000..3c966e6 --- /dev/null +++ b/leetcode/daily_temperatures/playground.ipynb @@ -0,0 +1,57 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "fe9541a0", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_daily_temperatures, run_daily_temperatures\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a5124b73", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "temperatures = [73, 74, 75, 71, 69, 72, 76, 73]\n", + "expected = [1, 1, 4, 2, 1, 1, 0, 0]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8fc8c774", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_daily_temperatures(Solution, temperatures)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1c127161", + "metadata": {}, + "outputs": [], + "source": [ + "assert_daily_temperatures(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/decode_string/playground.ipynb b/leetcode/decode_string/playground.ipynb new file mode 100644 index 0000000..857ba6d --- /dev/null +++ b/leetcode/decode_string/playground.ipynb @@ -0,0 +1,57 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "99f992b8", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_decode_string, run_decode_string\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "80ee8b96", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "s = \"3[a]2[bc]\"\n", + "expected = \"aaabcbc\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9c175c84", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_decode_string(Solution, s)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4337c061", + "metadata": {}, + "outputs": [], + "source": [ + "assert_decode_string(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/decode_ways/playground.ipynb b/leetcode/decode_ways/playground.ipynb new file mode 100644 index 0000000..6064e99 --- /dev/null +++ b/leetcode/decode_ways/playground.ipynb @@ -0,0 +1,57 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "5acd1ce6", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_num_decodings, run_num_decodings\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6370ab15", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "s = \"226\"\n", + "expected = 3" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b9720bfe", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_num_decodings(Solution, s)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6e7d35d0", + "metadata": {}, + "outputs": [], + "source": [ + "assert_num_decodings(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/design_add_and_search_words_data_structure/playground.ipynb b/leetcode/design_add_and_search_words_data_structure/playground.ipynb new file mode 100644 index 0000000..c90d3a4 --- /dev/null +++ b/leetcode/design_add_and_search_words_data_structure/playground.ipynb @@ -0,0 +1,58 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "aebbee5f", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_word_dictionary, run_word_dictionary\n", + "from solution import WordDictionary" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7886928a", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "operations = [\"WordDictionary\", \"addWord\", \"addWord\", \"addWord\", \"search\", \"search\", \"search\", \"search\"]\n", + "inputs = [[], [\"bad\"], [\"dad\"], [\"mad\"], [\"pad\"], [\"bad\"], [\".ad\"], [\"b..\"]]\n", + "expected = [None, None, None, None, False, True, True, True]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "37cec089", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_word_dictionary(WordDictionary, operations, inputs)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "eb377909", + "metadata": {}, + "outputs": [], + "source": [ + "assert_word_dictionary(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/design_in_memory_file_system/playground.ipynb b/leetcode/design_in_memory_file_system/playground.ipynb new file mode 100644 index 0000000..5aaf93e --- /dev/null +++ b/leetcode/design_in_memory_file_system/playground.ipynb @@ -0,0 +1,59 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "2e611d9a", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_file_system, run_file_system\n", + "from solution import FileSystem" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8f757be1", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "operations = [\"FileSystem\", \"ls\", \"mkdir\", \"addContentToFile\", \"ls\", \"readContentFromFile\"]\n", + "inputs = [[], [\"/\"], [\"/a/b/c\"], [\"/a/b/c/d\", \"hello\"], [\"/\"], [\"/a/b/c/d\"]]\n", + "expected = [None, [], None, None, [\"a\"], \"hello\"]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c0b029e2", + "metadata": {}, + "outputs": [], + "source": [ + "result, fs = run_file_system(FileSystem, operations, inputs)\n", + "print(result)\n", + "fs" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ac29b56f", + "metadata": {}, + "outputs": [], + "source": [ + "assert_file_system(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/diagonal_traverse/playground.ipynb b/leetcode/diagonal_traverse/playground.ipynb new file mode 100644 index 0000000..4bfc14d --- /dev/null +++ b/leetcode/diagonal_traverse/playground.ipynb @@ -0,0 +1,57 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "4b23746b", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_find_diagonal_order, run_find_diagonal_order\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e68584f6", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "mat = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]\n", + "expected = [1, 2, 4, 7, 5, 3, 6, 8, 9]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b323b769", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_find_diagonal_order(Solution, mat)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "554c34ea", + "metadata": {}, + "outputs": [], + "source": [ + "assert_find_diagonal_order(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/diameter_of_binary_tree/playground.ipynb b/leetcode/diameter_of_binary_tree/playground.ipynb new file mode 100644 index 0000000..7ca7003 --- /dev/null +++ b/leetcode/diameter_of_binary_tree/playground.ipynb @@ -0,0 +1,60 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "f52a9bd1", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_diameter_of_binary_tree, run_diameter_of_binary_tree\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6e2bfe0a", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "root_list: list[int | None] = [1, 2, 3, 4, 5]\n", + "expected = 3" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9edac9cb", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_diameter_of_binary_tree(Solution, root_list)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8ea46c64", + "metadata": {}, + "outputs": [], + "source": [ + "assert_diameter_of_binary_tree(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/evaluate_reverse_polish_notation/playground.ipynb b/leetcode/evaluate_reverse_polish_notation/playground.ipynb new file mode 100644 index 0000000..bf43bbb --- /dev/null +++ b/leetcode/evaluate_reverse_polish_notation/playground.ipynb @@ -0,0 +1,60 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "cd841d34", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_eval_rpn, run_eval_rpn\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "dc5c14da", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "tokens = [\"2\", \"1\", \"+\", \"3\", \"*\"]\n", + "expected = 9" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d967ab88", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_eval_rpn(Solution, tokens)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c0130a96", + "metadata": {}, + "outputs": [], + "source": [ + "assert_eval_rpn(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/find_all_anagrams_in_a_string/playground.ipynb b/leetcode/find_all_anagrams_in_a_string/playground.ipynb new file mode 100644 index 0000000..710612a --- /dev/null +++ b/leetcode/find_all_anagrams_in_a_string/playground.ipynb @@ -0,0 +1,58 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "43293c0e", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_find_anagrams, run_find_anagrams\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d45b762f", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "s = \"cbaebabacd\"\n", + "p = \"abc\"\n", + "expected = [0, 6]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5420f66e", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_find_anagrams(Solution, s, p)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3564620a", + "metadata": {}, + "outputs": [], + "source": [ + "assert_find_anagrams(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/find_k_closest_elements/playground.ipynb b/leetcode/find_k_closest_elements/playground.ipynb new file mode 100644 index 0000000..2b6a89f --- /dev/null +++ b/leetcode/find_k_closest_elements/playground.ipynb @@ -0,0 +1,59 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "8acce8ed", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_find_closest_elements, run_find_closest_elements\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "29129dbc", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "arr = [1, 2, 3, 4, 5]\n", + "k = 4\n", + "x = 3\n", + "expected = [1, 2, 3, 4]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e2647ba0", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_find_closest_elements(Solution, arr, k, x)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6ffb71eb", + "metadata": {}, + "outputs": [], + "source": [ + "assert_find_closest_elements(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/find_median_from_data_stream/playground.ipynb b/leetcode/find_median_from_data_stream/playground.ipynb new file mode 100644 index 0000000..d2fe0cb --- /dev/null +++ b/leetcode/find_median_from_data_stream/playground.ipynb @@ -0,0 +1,62 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "5a45206e", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_median_finder, run_median_finder\n", + "from solution import MedianFinder" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0aada4e4", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "operations = [\"MedianFinder\", \"addNum\", \"addNum\", \"findMedian\", \"addNum\", \"findMedian\"]\n", + "inputs = [[], [1], [2], [], [3], []]\n", + "expected = [None, None, None, 1.5, None, 2.0]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8d764ec6", + "metadata": {}, + "outputs": [], + "source": [ + "result, mf = run_median_finder(MedianFinder, operations, inputs)\n", + "print(result)\n", + "mf" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "066d7641", + "metadata": {}, + "outputs": [], + "source": [ + "assert_median_finder(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/find_minimum_in_rotated_sorted_array/playground.ipynb b/leetcode/find_minimum_in_rotated_sorted_array/playground.ipynb new file mode 100644 index 0000000..0b5ec09 --- /dev/null +++ b/leetcode/find_minimum_in_rotated_sorted_array/playground.ipynb @@ -0,0 +1,57 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "676d2936", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_find_min, run_find_min\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e1a22001", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "nums: list[int] = [3, 4, 5, 1, 2]\n", + "expected: int = 1" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e33347c6", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_find_min(Solution, nums)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b956f92f", + "metadata": {}, + "outputs": [], + "source": [ + "assert_find_min(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/find_the_duplicate_number/playground.ipynb b/leetcode/find_the_duplicate_number/playground.ipynb new file mode 100644 index 0000000..01368e7 --- /dev/null +++ b/leetcode/find_the_duplicate_number/playground.ipynb @@ -0,0 +1,57 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "429167f0", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_find_duplicate, run_find_duplicate\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ed9fc5cb", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "nums: list[int] = [1, 3, 4, 2, 2]\n", + "expected = 2" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3ee2cc0c", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_find_duplicate(Solution, nums)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e2c04ded", + "metadata": {}, + "outputs": [], + "source": [ + "assert_find_duplicate(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/first_bad_version/playground.ipynb b/leetcode/first_bad_version/playground.ipynb new file mode 100644 index 0000000..8d9a6ed --- /dev/null +++ b/leetcode/first_bad_version/playground.ipynb @@ -0,0 +1,61 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "71a9ac55", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_first_bad_version, run_first_bad_version\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "019eddf2", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "n = 5\n", + "bad = 4\n", + "expected = 4" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3a1a99de", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_first_bad_version(Solution, n, bad)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d1a830e6", + "metadata": {}, + "outputs": [], + "source": [ + "assert_first_bad_version(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/flood_fill/playground.ipynb b/leetcode/flood_fill/playground.ipynb new file mode 100644 index 0000000..2b37fd9 --- /dev/null +++ b/leetcode/flood_fill/playground.ipynb @@ -0,0 +1,63 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "c5385be4", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_flood_fill, run_flood_fill\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e6529527", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "image = [[1, 1, 1], [1, 1, 0], [1, 0, 1]]\n", + "sr = 1\n", + "sc = 1\n", + "color = 2\n", + "expected = [[2, 2, 2], [2, 2, 0], [2, 0, 1]]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c5788a74", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_flood_fill(Solution, image, sr, sc, color)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cbea39a1", + "metadata": {}, + "outputs": [], + "source": [ + "assert_flood_fill(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/gas_station/playground.ipynb b/leetcode/gas_station/playground.ipynb new file mode 100644 index 0000000..242d48d --- /dev/null +++ b/leetcode/gas_station/playground.ipynb @@ -0,0 +1,58 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "c2515ccc", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_can_complete_circuit, run_can_complete_circuit\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "089ff886", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "gas = [1, 2, 3, 4, 5]\n", + "cost = [3, 4, 5, 1, 2]\n", + "expected = 3" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e698b085", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_can_complete_circuit(Solution, gas, cost)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7c4cca4c", + "metadata": {}, + "outputs": [], + "source": [ + "assert_can_complete_circuit(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/group_anagrams/playground.ipynb b/leetcode/group_anagrams/playground.ipynb new file mode 100644 index 0000000..ea843bb --- /dev/null +++ b/leetcode/group_anagrams/playground.ipynb @@ -0,0 +1,57 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "c2b50a23", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_group_anagrams, run_group_anagrams\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ec5283b8", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "strs = [\"eat\", \"tea\", \"tan\", \"ate\", \"nat\", \"bat\"]\n", + "expected = [[\"bat\"], [\"nat\", \"tan\"], [\"ate\", \"eat\", \"tea\"]]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "93ee9681", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_group_anagrams(Solution, strs)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c507972b", + "metadata": {}, + "outputs": [], + "source": [ + "assert_group_anagrams(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/house_robber/playground.ipynb b/leetcode/house_robber/playground.ipynb new file mode 100644 index 0000000..622ff81 --- /dev/null +++ b/leetcode/house_robber/playground.ipynb @@ -0,0 +1,57 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "bf7608aa", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_rob, run_rob\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7c116e6d", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "nums = [2, 7, 9, 3, 1]\n", + "expected = 12" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "53431418", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_rob(Solution, nums)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "96c8c4bd", + "metadata": {}, + "outputs": [], + "source": [ + "assert_rob(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/house_robber_ii/playground.ipynb b/leetcode/house_robber_ii/playground.ipynb new file mode 100644 index 0000000..baa1b4a --- /dev/null +++ b/leetcode/house_robber_ii/playground.ipynb @@ -0,0 +1,57 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "bcdd5c17", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_rob, run_rob\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "52eb2c42", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "nums = [2, 3, 2]\n", + "expected = 3" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b899cdba", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_rob(Solution, nums)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cdd6c4db", + "metadata": {}, + "outputs": [], + "source": [ + "assert_rob(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/implement_queue_using_stacks/playground.ipynb b/leetcode/implement_queue_using_stacks/playground.ipynb new file mode 100644 index 0000000..ee07182 --- /dev/null +++ b/leetcode/implement_queue_using_stacks/playground.ipynb @@ -0,0 +1,62 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "89c715e8", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_my_queue, run_my_queue\n", + "from solution import MyQueue" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e7b25816", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "operations = [\"MyQueue\", \"push\", \"push\", \"peek\", \"pop\", \"empty\"]\n", + "inputs = [[], [1], [2], [], [], []]\n", + "expected = [None, None, None, 1, 1, False]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e7f10dbc", + "metadata": {}, + "outputs": [], + "source": [ + "result, queue = run_my_queue(MyQueue, operations, inputs)\n", + "print(result)\n", + "queue" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b30bacec", + "metadata": {}, + "outputs": [], + "source": [ + "assert_my_queue(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/implement_trie_prefix_tree/playground.ipynb b/leetcode/implement_trie_prefix_tree/playground.ipynb new file mode 100644 index 0000000..535de31 --- /dev/null +++ b/leetcode/implement_trie_prefix_tree/playground.ipynb @@ -0,0 +1,62 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "474f2fb3", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_trie_operations, run_trie_operations\n", + "from solution import Trie" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fbcd683e", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "operations = [\"Trie\", \"insert\", \"search\", \"search\", \"starts_with\", \"insert\", \"search\"]\n", + "inputs = [[], [\"apple\"], [\"apple\"], [\"app\"], [\"app\"], [\"app\"], [\"app\"]]\n", + "expected = [None, None, True, False, True, None, True]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "518adcbc", + "metadata": {}, + "outputs": [], + "source": [ + "result, trie = run_trie_operations(Trie, operations, inputs)\n", + "print(result)\n", + "trie" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "deb75720", + "metadata": {}, + "outputs": [], + "source": [ + "assert_trie_operations(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/insert_interval/playground.ipynb b/leetcode/insert_interval/playground.ipynb new file mode 100644 index 0000000..89b21cd --- /dev/null +++ b/leetcode/insert_interval/playground.ipynb @@ -0,0 +1,61 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "c7e30b64", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_insert, run_insert\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7371e4e5", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "intervals = [[1, 3], [6, 9]]\n", + "new_interval = [2, 5]\n", + "expected = [[1, 5], [6, 9]]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ece85b6b", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_insert(Solution, intervals, new_interval)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3931572c", + "metadata": {}, + "outputs": [], + "source": [ + "assert_insert(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/invert_binary_tree/playground.ipynb b/leetcode/invert_binary_tree/playground.ipynb new file mode 100644 index 0000000..538b29a --- /dev/null +++ b/leetcode/invert_binary_tree/playground.ipynb @@ -0,0 +1,194 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "1cbfdcb9", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_invert_tree, run_invert_tree\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "af3f56f6", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "root_list: list[int | None] = [4, 2, 7, 1, 3, 6, 9]\n", + "expected_list: list[int | None] = [4, 7, 2, 9, 6, 3, 1]" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "47122808", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "0\n", + "\n", + "4\n", + "\n", + "\n", + "\n", + "1\n", + "\n", + "7\n", + "\n", + "\n", + "\n", + "0->1\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "4\n", + "\n", + "2\n", + "\n", + "\n", + "\n", + "0->4\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "2\n", + "\n", + "9\n", + "\n", + "\n", + "\n", + "1->2\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "3\n", + "\n", + "6\n", + "\n", + "\n", + "\n", + "1->3\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "5\n", + "\n", + "3\n", + "\n", + "\n", + "\n", + "4->5\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "6\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "4->6\n", + "\n", + "\n", + "\n", + "\n", + "\n" + ], + "text/plain": [ + "TreeNode([4, 7, 2, 9, 6, 3, 1])" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "result = run_invert_tree(Solution, root_list)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "a8cc705c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "assert_invert_tree(result, expected_list)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "88625b9b", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-env (3.13.7)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.13.7" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/jump_game/playground.ipynb b/leetcode/jump_game/playground.ipynb new file mode 100644 index 0000000..49a5987 --- /dev/null +++ b/leetcode/jump_game/playground.ipynb @@ -0,0 +1,57 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "4c250240", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_can_jump, run_can_jump\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "994b9334", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "nums = [2, 3, 1, 1, 4]\n", + "expected = True" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5df56f18", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_can_jump(Solution, nums)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "975022f6", + "metadata": {}, + "outputs": [], + "source": [ + "assert_can_jump(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/k_closest_points_to_origin/playground.ipynb b/leetcode/k_closest_points_to_origin/playground.ipynb new file mode 100644 index 0000000..f530366 --- /dev/null +++ b/leetcode/k_closest_points_to_origin/playground.ipynb @@ -0,0 +1,61 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "b409e442", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_k_closest, run_k_closest\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b76f402d", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "points = [[1, 3], [-2, 2]]\n", + "k = 1\n", + "expected = [[-2, 2]]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fa8b3e3b", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_k_closest(Solution, points, k)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "93819cd8", + "metadata": {}, + "outputs": [], + "source": [ + "assert_k_closest(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/kth_smallest_element_in_a_bst/playground.ipynb b/leetcode/kth_smallest_element_in_a_bst/playground.ipynb new file mode 100644 index 0000000..0032a9f --- /dev/null +++ b/leetcode/kth_smallest_element_in_a_bst/playground.ipynb @@ -0,0 +1,61 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "d9317014", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_kth_smallest, run_kth_smallest\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e022df0e", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "root_list = [3, 1, 4, None, 2]\n", + "k = 1\n", + "expected = 1" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6451a554", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_kth_smallest(Solution, root_list, k)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "dda46b06", + "metadata": {}, + "outputs": [], + "source": [ + "assert_kth_smallest(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/largest_rectangle_in_histogram/playground.ipynb b/leetcode/largest_rectangle_in_histogram/playground.ipynb new file mode 100644 index 0000000..8e3add7 --- /dev/null +++ b/leetcode/largest_rectangle_in_histogram/playground.ipynb @@ -0,0 +1,60 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "83d7d4a3", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_largest_rectangle_area, run_largest_rectangle_area\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b15c6c23", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "heights = [2, 1, 5, 6, 2, 3]\n", + "expected = 10" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c09a8558", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_largest_rectangle_area(Solution, heights)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fb64ed17", + "metadata": {}, + "outputs": [], + "source": [ + "assert_largest_rectangle_area(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/letter_combinations_of_a_phone_number/playground.ipynb b/leetcode/letter_combinations_of_a_phone_number/playground.ipynb new file mode 100644 index 0000000..94df8b2 --- /dev/null +++ b/leetcode/letter_combinations_of_a_phone_number/playground.ipynb @@ -0,0 +1,57 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "2f8936d3", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_letter_combinations, run_letter_combinations\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1d546901", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "digits = \"23\"\n", + "expected = [\"ad\", \"ae\", \"af\", \"bd\", \"be\", \"bf\", \"cd\", \"ce\", \"cf\"]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3a0a4b36", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_letter_combinations(Solution, digits)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f2aefc87", + "metadata": {}, + "outputs": [], + "source": [ + "assert_letter_combinations(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/linked_list_cycle/playground.ipynb b/leetcode/linked_list_cycle/playground.ipynb new file mode 100644 index 0000000..65b092a --- /dev/null +++ b/leetcode/linked_list_cycle/playground.ipynb @@ -0,0 +1,72 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "fd5f7e8d", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_has_cycle, create_cycle_list, run_has_cycle\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b476008f", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "values = [3, 2, 0, -4]\n", + "pos = 1\n", + "expected = True" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "61af81b8", + "metadata": {}, + "outputs": [], + "source": [ + "head = create_cycle_list(values, pos)\n", + "head" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6e1ec49c", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_has_cycle(Solution, values, pos)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c390c71c", + "metadata": {}, + "outputs": [], + "source": [ + "assert_has_cycle(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/longest_common_subsequence/playground.ipynb b/leetcode/longest_common_subsequence/playground.ipynb new file mode 100644 index 0000000..e71dcf1 --- /dev/null +++ b/leetcode/longest_common_subsequence/playground.ipynb @@ -0,0 +1,58 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "c2820bbf", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_longest_common_subsequence, run_longest_common_subsequence\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "36d763c4", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "text1 = \"abcde\"\n", + "text2 = \"ace\"\n", + "expected = 3" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9dfc1fb6", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_longest_common_subsequence(Solution, text1, text2)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fb1432e4", + "metadata": {}, + "outputs": [], + "source": [ + "assert_longest_common_subsequence(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/longest_consecutive_sequence/playground.ipynb b/leetcode/longest_consecutive_sequence/playground.ipynb new file mode 100644 index 0000000..4a7af35 --- /dev/null +++ b/leetcode/longest_consecutive_sequence/playground.ipynb @@ -0,0 +1,57 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "05e7ff2a", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_longest_consecutive, run_longest_consecutive\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "940e5827", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "nums = [100, 4, 200, 1, 3, 2]\n", + "expected = 4" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fcb5d440", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_longest_consecutive(Solution, nums)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "63af43fd", + "metadata": {}, + "outputs": [], + "source": [ + "assert_longest_consecutive(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/longest_increasing_subsequence/playground.ipynb b/leetcode/longest_increasing_subsequence/playground.ipynb new file mode 100644 index 0000000..bcfcd69 --- /dev/null +++ b/leetcode/longest_increasing_subsequence/playground.ipynb @@ -0,0 +1,57 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "7b2ee9b7", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_length_of_lis, run_length_of_lis\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8d3a0b7a", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "nums = [10, 9, 2, 5, 3, 7, 101, 18]\n", + "expected = 4" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7ea90fe3", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_length_of_lis(Solution, nums)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "093b1a14", + "metadata": {}, + "outputs": [], + "source": [ + "assert_length_of_lis(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/longest_palindrome/playground.ipynb b/leetcode/longest_palindrome/playground.ipynb new file mode 100644 index 0000000..91717c0 --- /dev/null +++ b/leetcode/longest_palindrome/playground.ipynb @@ -0,0 +1,60 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "f9cb66f0", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_longest_palindrome, run_longest_palindrome\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1f72e2bf", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "s = \"abccccdd\"\n", + "expected = 7" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4c3182a1", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_longest_palindrome(Solution, s)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8b88a907", + "metadata": {}, + "outputs": [], + "source": [ + "assert_longest_palindrome(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/longest_palindromic_substring/playground.ipynb b/leetcode/longest_palindromic_substring/playground.ipynb new file mode 100644 index 0000000..7dd575e --- /dev/null +++ b/leetcode/longest_palindromic_substring/playground.ipynb @@ -0,0 +1,60 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "a8e2807c", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_longest_palindrome, run_longest_palindrome\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "247dad58", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "s = \"babad\"\n", + "expected = {\"bab\", \"aba\"}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fd527c64", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_longest_palindrome(Solution, s)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6e410a62", + "metadata": {}, + "outputs": [], + "source": [ + "assert_longest_palindrome(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/longest_repeating_character_replacement/playground.ipynb b/leetcode/longest_repeating_character_replacement/playground.ipynb new file mode 100644 index 0000000..7dc0fc8 --- /dev/null +++ b/leetcode/longest_repeating_character_replacement/playground.ipynb @@ -0,0 +1,58 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "1c8b4db0", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_character_replacement, run_character_replacement\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f47bd368", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "s = \"ABAB\"\n", + "k = 2\n", + "expected = 4" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cbfd9280", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_character_replacement(Solution, s, k)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "783f5aed", + "metadata": {}, + "outputs": [], + "source": [ + "assert_character_replacement(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/longest_substring_without_repeating_characters/playground.ipynb b/leetcode/longest_substring_without_repeating_characters/playground.ipynb new file mode 100644 index 0000000..81ad396 --- /dev/null +++ b/leetcode/longest_substring_without_repeating_characters/playground.ipynb @@ -0,0 +1,60 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "bedfe811", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_length_of_longest_substring, run_length_of_longest_substring\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e981e82c", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "s = \"abcabcbb\"\n", + "expected = 3" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "72aad514", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_length_of_longest_substring(Solution, s)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "346256e0", + "metadata": {}, + "outputs": [], + "source": [ + "assert_length_of_longest_substring(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/lowest_common_ancestor_of_a_binary_search_tree/playground.ipynb b/leetcode/lowest_common_ancestor_of_a_binary_search_tree/playground.ipynb new file mode 100644 index 0000000..99de9a9 --- /dev/null +++ b/leetcode/lowest_common_ancestor_of_a_binary_search_tree/playground.ipynb @@ -0,0 +1,62 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "1c99ec5b", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_lowest_common_ancestor, run_lowest_common_ancestor\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "82b4e6cc", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "root_list = [6, 2, 8, 0, 4, 7, 9, None, None, 3, 5]\n", + "p_val = 2\n", + "q_val = 8\n", + "expected_val = 6" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cc5ab2fd", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_lowest_common_ancestor(Solution, root_list, p_val, q_val)\n", + "result.val if result else None" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c221bbe3", + "metadata": {}, + "outputs": [], + "source": [ + "assert_lowest_common_ancestor(result, expected_val)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/lowest_common_ancestor_of_a_binary_tree/playground.ipynb b/leetcode/lowest_common_ancestor_of_a_binary_tree/playground.ipynb new file mode 100644 index 0000000..839f9b6 --- /dev/null +++ b/leetcode/lowest_common_ancestor_of_a_binary_tree/playground.ipynb @@ -0,0 +1,62 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "a455f44b", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_lowest_common_ancestor, run_lowest_common_ancestor\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f4206617", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "root_list = [3, 5, 1, 6, 2, 0, 8, None, None, 7, 4]\n", + "p_val = 5\n", + "q_val = 1\n", + "expected_val = 3" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7c4547eb", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_lowest_common_ancestor(Solution, root_list, p_val, q_val)\n", + "result.val" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "424843cf", + "metadata": {}, + "outputs": [], + "source": [ + "assert_lowest_common_ancestor(result, expected_val)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/lru_cache/playground.ipynb b/leetcode/lru_cache/playground.ipynb new file mode 100644 index 0000000..e3f7005 --- /dev/null +++ b/leetcode/lru_cache/playground.ipynb @@ -0,0 +1,62 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "9721c467", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_lru_cache, run_lru_cache\n", + "from solution import LRUCache" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "98532277", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "operations = [\"LRUCache\", \"put\", \"put\", \"get\", \"put\", \"get\", \"put\", \"get\", \"get\", \"get\"]\n", + "inputs = [[2], [1, 1], [2, 2], [1], [3, 3], [2], [4, 4], [1], [3], [4]]\n", + "expected = [None, None, None, 1, None, -1, None, -1, 3, 4]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f741d637", + "metadata": {}, + "outputs": [], + "source": [ + "result, cache = run_lru_cache(LRUCache, operations, inputs)\n", + "print(result)\n", + "cache.cache" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6e04aa41", + "metadata": {}, + "outputs": [], + "source": [ + "assert_lru_cache(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/majority_element/playground.ipynb b/leetcode/majority_element/playground.ipynb new file mode 100644 index 0000000..bf6e643 --- /dev/null +++ b/leetcode/majority_element/playground.ipynb @@ -0,0 +1,60 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "a9d65670", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_majority_element, run_majority_element\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4ba358b6", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "nums = [3, 2, 3]\n", + "expected = 3" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "78f28d02", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_majority_element(Solution, nums)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "abecae9b", + "metadata": {}, + "outputs": [], + "source": [ + "assert_majority_element(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/maximum_depth_of_binary_tree/playground.ipynb b/leetcode/maximum_depth_of_binary_tree/playground.ipynb new file mode 100644 index 0000000..247353d --- /dev/null +++ b/leetcode/maximum_depth_of_binary_tree/playground.ipynb @@ -0,0 +1,60 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "3fd6d866", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_max_depth, run_max_depth\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "69368198", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "root_list = [3, 9, 20, None, None, 15, 7]\n", + "expected = 3" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "dc0b04cf", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_max_depth(Solution, root_list)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6352926d", + "metadata": {}, + "outputs": [], + "source": [ + "assert_max_depth(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/maximum_product_subarray/playground.ipynb b/leetcode/maximum_product_subarray/playground.ipynb new file mode 100644 index 0000000..9f646bf --- /dev/null +++ b/leetcode/maximum_product_subarray/playground.ipynb @@ -0,0 +1,57 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "a03b2617", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_max_product, run_max_product\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2fd7255b", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "nums = [2, 3, -2, 4]\n", + "expected = 6" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "208a5e83", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_max_product(Solution, nums)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "49d7ce69", + "metadata": {}, + "outputs": [], + "source": [ + "assert_max_product(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/maximum_profit_in_job_scheduling/playground.ipynb b/leetcode/maximum_profit_in_job_scheduling/playground.ipynb new file mode 100644 index 0000000..df3566d --- /dev/null +++ b/leetcode/maximum_profit_in_job_scheduling/playground.ipynb @@ -0,0 +1,62 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "72b5f596", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_job_scheduling, run_job_scheduling\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a413adae", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "start_time = [1, 2, 3, 3]\n", + "end_time = [3, 4, 5, 6]\n", + "profit = [50, 10, 40, 70]\n", + "expected = 120" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6bfcc374", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_job_scheduling(Solution, start_time, end_time, profit)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "77768c9c", + "metadata": {}, + "outputs": [], + "source": [ + "assert_job_scheduling(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/maximum_subarray/playground.ipynb b/leetcode/maximum_subarray/playground.ipynb new file mode 100644 index 0000000..17af663 --- /dev/null +++ b/leetcode/maximum_subarray/playground.ipynb @@ -0,0 +1,60 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "4c4a5b75", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_max_sub_array, run_max_sub_array\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5d33beb7", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "nums = [-2, 1, -3, 4, -1, 2, 1, -5, 4]\n", + "expected = 6" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ee1c70ed", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_max_sub_array(Solution, nums)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6dc89d1a", + "metadata": {}, + "outputs": [], + "source": [ + "assert_max_sub_array(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/maximum_width_of_binary_tree/playground.ipynb b/leetcode/maximum_width_of_binary_tree/playground.ipynb new file mode 100644 index 0000000..66b7fb8 --- /dev/null +++ b/leetcode/maximum_width_of_binary_tree/playground.ipynb @@ -0,0 +1,57 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "f412f149", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_width_of_binary_tree, run_width_of_binary_tree\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f4e63747", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "root_list: list[int | None] = [1, 3, 2, 5, 3, None, 9]\n", + "expected = 4" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ec17531d", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_width_of_binary_tree(Solution, root_list)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ffbc0480", + "metadata": {}, + "outputs": [], + "source": [ + "assert_width_of_binary_tree(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/median_of_two_sorted_arrays/playground.ipynb b/leetcode/median_of_two_sorted_arrays/playground.ipynb new file mode 100644 index 0000000..d446fcc --- /dev/null +++ b/leetcode/median_of_two_sorted_arrays/playground.ipynb @@ -0,0 +1,58 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "fd5574b9", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_find_median_sorted_arrays, run_find_median_sorted_arrays\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "178d098d", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "nums1 = [1, 3]\n", + "nums2 = [2]\n", + "expected = 2.0" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "43c71c99", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_find_median_sorted_arrays(Solution, nums1, nums2)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6353cb8d", + "metadata": {}, + "outputs": [], + "source": [ + "assert_find_median_sorted_arrays(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/merge_intervals/playground.ipynb b/leetcode/merge_intervals/playground.ipynb new file mode 100644 index 0000000..3e8fb02 --- /dev/null +++ b/leetcode/merge_intervals/playground.ipynb @@ -0,0 +1,60 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "c2e63c5c", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_merge, run_merge\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "906f5114", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "intervals = [[1, 3], [2, 6], [8, 10], [15, 18]]\n", + "expected = [[1, 6], [8, 10], [15, 18]]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3418e5f7", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_merge(Solution, intervals)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e5ba835c", + "metadata": {}, + "outputs": [], + "source": [ + "assert_merge(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/merge_k_sorted_lists/playground.ipynb b/leetcode/merge_k_sorted_lists/playground.ipynb new file mode 100644 index 0000000..2e5dbd8 --- /dev/null +++ b/leetcode/merge_k_sorted_lists/playground.ipynb @@ -0,0 +1,62 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "cf3f6564", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_merge_k_lists, run_merge_k_lists\n", + "from solution import Solution\n", + "\n", + "from leetcode_py import ListNode" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "89841e8f", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "lists_data = [[1, 4, 5], [1, 3, 4], [2, 6]]\n", + "expected_data = [1, 1, 2, 3, 4, 4, 5, 6]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6bac8377", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_merge_k_lists(Solution, lists_data)\n", + "ListNode[int].to_list(result) if result else []" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "055355a5", + "metadata": {}, + "outputs": [], + "source": [ + "assert_merge_k_lists(result, expected_data)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/merge_two_sorted_lists/playground.ipynb b/leetcode/merge_two_sorted_lists/playground.ipynb new file mode 100644 index 0000000..ab27948 --- /dev/null +++ b/leetcode/merge_two_sorted_lists/playground.ipynb @@ -0,0 +1,63 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "6a2de4ed", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_merge_two_lists, run_merge_two_lists\n", + "from solution import Solution\n", + "\n", + "from leetcode_py import ListNode" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "eceb052a", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "list1_vals = [1, 2, 4]\n", + "list2_vals = [1, 3, 4]\n", + "expected_vals = [1, 1, 2, 3, 4, 4]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "328884e3", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_merge_two_lists(Solution, list1_vals, list2_vals)\n", + "ListNode[int].to_list(result) if result else []" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a509823d", + "metadata": {}, + "outputs": [], + "source": [ + "assert_merge_two_lists(result, expected_vals)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/middle_of_the_linked_list/playground.ipynb b/leetcode/middle_of_the_linked_list/playground.ipynb new file mode 100644 index 0000000..f2c47d6 --- /dev/null +++ b/leetcode/middle_of_the_linked_list/playground.ipynb @@ -0,0 +1,62 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "24f73b92", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_middle_node, run_middle_node\n", + "from solution import Solution\n", + "\n", + "from leetcode_py import ListNode" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e81bf622", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "head_list = [1, 2, 3, 4, 5]\n", + "expected_list = [3, 4, 5]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b9e51e78", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_middle_node(Solution, head_list)\n", + "ListNode[int].to_list(result) if result else []" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d187f812", + "metadata": {}, + "outputs": [], + "source": [ + "assert_middle_node(result, expected_list)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/min_stack/playground.ipynb b/leetcode/min_stack/playground.ipynb new file mode 100644 index 0000000..6488228 --- /dev/null +++ b/leetcode/min_stack/playground.ipynb @@ -0,0 +1,61 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "4e3e1bab", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_min_stack_operations, run_min_stack_operations\n", + "from solution import MinStack" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6e82829d", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "operations = [\"MinStack\", \"push\", \"push\", \"push\", \"getMin\", \"pop\", \"top\", \"getMin\"]\n", + "inputs = [[], [-2], [0], [-3], [], [], [], []]\n", + "expected = [None, None, None, None, -3, None, 0, -2]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a82c8832", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_min_stack_operations(MinStack, operations, inputs)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fafa956b", + "metadata": {}, + "outputs": [], + "source": [ + "assert_min_stack_operations(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/minimum_height_trees/playground.ipynb b/leetcode/minimum_height_trees/playground.ipynb new file mode 100644 index 0000000..0373e53 --- /dev/null +++ b/leetcode/minimum_height_trees/playground.ipynb @@ -0,0 +1,61 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "ea20c303", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_find_min_height_trees, run_find_min_height_trees\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "117bc725", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "n = 4\n", + "edges = [[1, 0], [1, 2], [1, 3]]\n", + "expected = [1]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b80dd7c3", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_find_min_height_trees(Solution, n, edges)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "65d7ee0c", + "metadata": {}, + "outputs": [], + "source": [ + "assert_find_min_height_trees(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/minimum_window_substring/playground.ipynb b/leetcode/minimum_window_substring/playground.ipynb new file mode 100644 index 0000000..bf79ed0 --- /dev/null +++ b/leetcode/minimum_window_substring/playground.ipynb @@ -0,0 +1,61 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "1863b0f0", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_min_window, run_min_window\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e6420770", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "s = \"ADOBECODEBANC\"\n", + "t = \"ABC\"\n", + "expected = \"BANC\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "76e8ffec", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_min_window(Solution, s, t)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d2512be1", + "metadata": {}, + "outputs": [], + "source": [ + "assert_min_window(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/missing_number/playground.ipynb b/leetcode/missing_number/playground.ipynb new file mode 100644 index 0000000..7b894ef --- /dev/null +++ b/leetcode/missing_number/playground.ipynb @@ -0,0 +1,57 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "c2bb0964", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_missing_number, run_missing_number\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ae28aa12", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "nums = [3, 0, 1]\n", + "expected = 2" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9ea85a3e", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_missing_number(Solution, nums)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7dd037e9", + "metadata": {}, + "outputs": [], + "source": [ + "assert_missing_number(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/next_permutation/playground.ipynb b/leetcode/next_permutation/playground.ipynb new file mode 100644 index 0000000..dc79ef9 --- /dev/null +++ b/leetcode/next_permutation/playground.ipynb @@ -0,0 +1,57 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "ef57a838", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_next_permutation, run_next_permutation\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b8d35add", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "nums = [1, 2, 3]\n", + "expected = [1, 3, 2]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3bc3aa23", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_next_permutation(Solution, nums)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5e5d1fa3", + "metadata": {}, + "outputs": [], + "source": [ + "assert_next_permutation(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/non_overlapping_intervals/playground.ipynb b/leetcode/non_overlapping_intervals/playground.ipynb new file mode 100644 index 0000000..dae4d8b --- /dev/null +++ b/leetcode/non_overlapping_intervals/playground.ipynb @@ -0,0 +1,57 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "462a8ceb", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_erase_overlap_intervals, run_erase_overlap_intervals\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6941c1e9", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "intervals = [[1, 2], [2, 3], [3, 4], [1, 3]]\n", + "expected = 1" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "116e9ecf", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_erase_overlap_intervals(Solution, intervals)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d1d3d0d1", + "metadata": {}, + "outputs": [], + "source": [ + "assert_erase_overlap_intervals(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/number_of_1_bits/playground.ipynb b/leetcode/number_of_1_bits/playground.ipynb new file mode 100644 index 0000000..99d6e66 --- /dev/null +++ b/leetcode/number_of_1_bits/playground.ipynb @@ -0,0 +1,57 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "9ee096a9", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_hamming_weight, run_hamming_weight\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fae30811", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "n = 11\n", + "expected = 3" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7d202e26", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_hamming_weight(Solution, n)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a1cad8f1", + "metadata": {}, + "outputs": [], + "source": [ + "assert_hamming_weight(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/number_of_islands/playground.ipynb b/leetcode/number_of_islands/playground.ipynb new file mode 100644 index 0000000..793f3f6 --- /dev/null +++ b/leetcode/number_of_islands/playground.ipynb @@ -0,0 +1,65 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "b5573ceb", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_num_islands, run_num_islands\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ca718fec", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "grid = [\n", + " [\"1\", \"1\", \"1\", \"1\", \"0\"],\n", + " [\"1\", \"1\", \"0\", \"1\", \"0\"],\n", + " [\"1\", \"1\", \"0\", \"0\", \"0\"],\n", + " [\"0\", \"0\", \"0\", \"0\", \"0\"],\n", + "]\n", + "expected = 1" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4cfbd3cf", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_num_islands(Solution, grid)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "84b33094", + "metadata": {}, + "outputs": [], + "source": [ + "assert_num_islands(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/odd_even_linked_list/playground.ipynb b/leetcode/odd_even_linked_list/playground.ipynb new file mode 100644 index 0000000..ee156ff --- /dev/null +++ b/leetcode/odd_even_linked_list/playground.ipynb @@ -0,0 +1,57 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "38ea1b6e", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_odd_even_list, run_odd_even_list\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ab2d7a36", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "head_list = [1, 2, 3, 4, 5]\n", + "expected = [1, 3, 5, 2, 4]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "78341805", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_odd_even_list(Solution, head_list)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "17580b67", + "metadata": {}, + "outputs": [], + "source": [ + "assert_odd_even_list(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/pacific_atlantic_water_flow/playground.ipynb b/leetcode/pacific_atlantic_water_flow/playground.ipynb new file mode 100644 index 0000000..3f1a182 --- /dev/null +++ b/leetcode/pacific_atlantic_water_flow/playground.ipynb @@ -0,0 +1,57 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "f0b70783", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_pacific_atlantic, run_pacific_atlantic\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "168c09e7", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "heights = [[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]]\n", + "expected = [[0, 4], [1, 3], [1, 4], [2, 2], [3, 0], [3, 1], [4, 0]]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9c68286c", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_pacific_atlantic(Solution, heights)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "defabc1f", + "metadata": {}, + "outputs": [], + "source": [ + "assert_pacific_atlantic(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/palindromic_substrings/playground.ipynb b/leetcode/palindromic_substrings/playground.ipynb new file mode 100644 index 0000000..9ea39bb --- /dev/null +++ b/leetcode/palindromic_substrings/playground.ipynb @@ -0,0 +1,57 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "bbeaed99", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_count_substrings, run_count_substrings\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "26ccf5b0", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "s = \"abc\"\n", + "expected = 3" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d183491a", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_count_substrings(Solution, s)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "069845b3", + "metadata": {}, + "outputs": [], + "source": [ + "assert_count_substrings(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/partition_equal_subset_sum/playground.ipynb b/leetcode/partition_equal_subset_sum/playground.ipynb new file mode 100644 index 0000000..87d7f8f --- /dev/null +++ b/leetcode/partition_equal_subset_sum/playground.ipynb @@ -0,0 +1,60 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "ea964ab7", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_can_partition, run_can_partition\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "248839de", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "nums = [1, 5, 11, 5]\n", + "expected = True" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b1e6e69e", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_can_partition(Solution, nums)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "911ae1e4", + "metadata": {}, + "outputs": [], + "source": [ + "assert_can_partition(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/path_sum_ii/playground.ipynb b/leetcode/path_sum_ii/playground.ipynb new file mode 100644 index 0000000..02f1e0d --- /dev/null +++ b/leetcode/path_sum_ii/playground.ipynb @@ -0,0 +1,58 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "8e853690", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_path_sum, run_path_sum\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "39088b85", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "root_list = [5, 4, 8, 11, None, 13, 4, 7, 2, None, None, 5, 1]\n", + "target_sum = 22\n", + "expected = [[5, 4, 11, 2], [5, 8, 4, 5]]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b57147b4", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_path_sum(Solution, root_list, target_sum)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ad8e9556", + "metadata": {}, + "outputs": [], + "source": [ + "assert_path_sum(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/permutations/playground.ipynb b/leetcode/permutations/playground.ipynb new file mode 100644 index 0000000..54d9faf --- /dev/null +++ b/leetcode/permutations/playground.ipynb @@ -0,0 +1,60 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "3ba83e82", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_permute, run_permute\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d471728c", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "nums = [1, 2, 3]\n", + "expected = [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7b4d4203", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_permute(Solution, nums)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b8bf02db", + "metadata": {}, + "outputs": [], + "source": [ + "assert_permute(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/product_of_array_except_self/playground.ipynb b/leetcode/product_of_array_except_self/playground.ipynb new file mode 100644 index 0000000..fe43632 --- /dev/null +++ b/leetcode/product_of_array_except_self/playground.ipynb @@ -0,0 +1,60 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "58c1bd07", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_product_except_self, run_product_except_self\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "39d52144", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "nums = [1, 2, 3, 4]\n", + "expected = [24, 12, 8, 6]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0ead5a9c", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_product_except_self(Solution, nums)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5a3cbd0b", + "metadata": {}, + "outputs": [], + "source": [ + "assert_product_except_self(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/ransom_note/playground.ipynb b/leetcode/ransom_note/playground.ipynb new file mode 100644 index 0000000..764cf7d --- /dev/null +++ b/leetcode/ransom_note/playground.ipynb @@ -0,0 +1,61 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "9039cc8e", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_can_construct, run_can_construct\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9563665e", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "ransom_note = \"aa\"\n", + "magazine = \"aab\"\n", + "expected = True" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0674fec7", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_can_construct(Solution, ransom_note, magazine)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0938f074", + "metadata": {}, + "outputs": [], + "source": [ + "assert_can_construct(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/remove_nth_node_from_end_of_list/playground.ipynb b/leetcode/remove_nth_node_from_end_of_list/playground.ipynb new file mode 100644 index 0000000..88de4d6 --- /dev/null +++ b/leetcode/remove_nth_node_from_end_of_list/playground.ipynb @@ -0,0 +1,58 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "da1959ed", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_remove_nth_from_end, run_remove_nth_from_end\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2a05769b", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "head_list: list[int] = [1, 2, 3, 4, 5]\n", + "n = 2\n", + "expected: list[int] = [1, 2, 3, 5]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "663dd8d0", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_remove_nth_from_end(Solution, head_list, n)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "240e0bd9", + "metadata": {}, + "outputs": [], + "source": [ + "assert_remove_nth_from_end(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/reorder_list/playground.ipynb b/leetcode/reorder_list/playground.ipynb new file mode 100644 index 0000000..ce187b7 --- /dev/null +++ b/leetcode/reorder_list/playground.ipynb @@ -0,0 +1,57 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "6706022b", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_reorder_list, run_reorder_list\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5ee1e32c", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "head_list: list[int] = [1, 2, 3, 4]\n", + "expected: list[int] = [1, 4, 2, 3]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9c549f2d", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_reorder_list(Solution, head_list)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "85154bda", + "metadata": {}, + "outputs": [], + "source": [ + "assert_reorder_list(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/reverse_bits/playground.ipynb b/leetcode/reverse_bits/playground.ipynb new file mode 100644 index 0000000..51e9ef9 --- /dev/null +++ b/leetcode/reverse_bits/playground.ipynb @@ -0,0 +1,57 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "6bfcf37a", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_reverse_bits, run_reverse_bits\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "770471fb", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "n: int = 43261596\n", + "expected: int = 964176192" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6137c273", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_reverse_bits(Solution, n)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6e5c1923", + "metadata": {}, + "outputs": [], + "source": [ + "assert_reverse_bits(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/reverse_integer/playground.ipynb b/leetcode/reverse_integer/playground.ipynb new file mode 100644 index 0000000..82cb098 --- /dev/null +++ b/leetcode/reverse_integer/playground.ipynb @@ -0,0 +1,57 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "89878aca", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_reverse, run_reverse\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "028e073e", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "x = 123\n", + "expected = 321" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "00ac6cfa", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_reverse(Solution, x)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7bbf6f67", + "metadata": {}, + "outputs": [], + "source": [ + "assert_reverse(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/reverse_linked_list/playground.ipynb b/leetcode/reverse_linked_list/playground.ipynb new file mode 100644 index 0000000..db4514a --- /dev/null +++ b/leetcode/reverse_linked_list/playground.ipynb @@ -0,0 +1,60 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "e84db794", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_reverse_list, run_reverse_list\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "edb6f9ee", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "head_list = [1, 2, 3, 4, 5]\n", + "expected_list = [5, 4, 3, 2, 1]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8f0bd42d", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_reverse_list(Solution, head_list)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0ab1ff09", + "metadata": {}, + "outputs": [], + "source": [ + "assert_reverse_list(result, expected_list)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/reverse_linked_list_ii/playground.ipynb b/leetcode/reverse_linked_list_ii/playground.ipynb new file mode 100644 index 0000000..ef8eac0 --- /dev/null +++ b/leetcode/reverse_linked_list_ii/playground.ipynb @@ -0,0 +1,61 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "034b6ead", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_reverse_between, run_reverse_between\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fe9d3a0a", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "head_list = [1, 2, 3, 4, 5]\n", + "left, right = 2, 4\n", + "expected_list = [1, 4, 3, 2, 5]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a2ecaf95", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_reverse_between(Solution, head_list, left, right)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ee0ae3c7", + "metadata": {}, + "outputs": [], + "source": [ + "assert_reverse_between(result, expected_list)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/reverse_nodes_in_k_group/playground.ipynb b/leetcode/reverse_nodes_in_k_group/playground.ipynb new file mode 100644 index 0000000..9a1e09f --- /dev/null +++ b/leetcode/reverse_nodes_in_k_group/playground.ipynb @@ -0,0 +1,58 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "8ac297d5", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_reverse_k_group, run_reverse_k_group\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2008085a", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "head_vals = [1, 2, 3, 4, 5]\n", + "k = 2\n", + "expected_vals = [2, 1, 4, 3, 5]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "98f1a664", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_reverse_k_group(Solution, head_vals, k)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "35233728", + "metadata": {}, + "outputs": [], + "source": [ + "assert_reverse_k_group(result, expected_vals)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/rotate_array/playground.ipynb b/leetcode/rotate_array/playground.ipynb new file mode 100644 index 0000000..869a355 --- /dev/null +++ b/leetcode/rotate_array/playground.ipynb @@ -0,0 +1,58 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "6f5dedc4", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_rotate, run_rotate\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e46797e6", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "nums = [1, 2, 3, 4, 5, 6, 7]\n", + "k = 3\n", + "expected = [5, 6, 7, 1, 2, 3, 4]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3dac1d75", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_rotate(Solution, nums, k)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5d561e99", + "metadata": {}, + "outputs": [], + "source": [ + "assert_rotate(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/rotate_image/playground.ipynb b/leetcode/rotate_image/playground.ipynb new file mode 100644 index 0000000..b02bd1a --- /dev/null +++ b/leetcode/rotate_image/playground.ipynb @@ -0,0 +1,57 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "15619dfd", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_rotate, run_rotate\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f907627f", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]\n", + "expected = [[7, 4, 1], [8, 5, 2], [9, 6, 3]]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e45cf3d4", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_rotate(Solution, matrix)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ce5d5adb", + "metadata": {}, + "outputs": [], + "source": [ + "assert_rotate(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/rotting_oranges/playground.ipynb b/leetcode/rotting_oranges/playground.ipynb new file mode 100644 index 0000000..bf982dd --- /dev/null +++ b/leetcode/rotting_oranges/playground.ipynb @@ -0,0 +1,60 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "7e096e0d", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_oranges_rotting, run_oranges_rotting\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "37dbb605", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "grid = [[2, 1, 1], [1, 1, 0], [0, 1, 1]]\n", + "expected = 4" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c04ea78b", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_oranges_rotting(Solution, grid)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "aa63f348", + "metadata": {}, + "outputs": [], + "source": [ + "assert_oranges_rotting(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/same_tree/playground.ipynb b/leetcode/same_tree/playground.ipynb new file mode 100644 index 0000000..76c7cd1 --- /dev/null +++ b/leetcode/same_tree/playground.ipynb @@ -0,0 +1,58 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "acded59d", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_is_same_tree, run_is_same_tree\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "28d0cabd", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "p_list: list[int | None] = [1, 2, 3]\n", + "q_list: list[int | None] = [1, 2, 3]\n", + "expected = True" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "69271839", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_is_same_tree(Solution, p_list, q_list)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4ed752d1", + "metadata": {}, + "outputs": [], + "source": [ + "assert_is_same_tree(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/search_in_rotated_sorted_array/playground.ipynb b/leetcode/search_in_rotated_sorted_array/playground.ipynb new file mode 100644 index 0000000..b16310a --- /dev/null +++ b/leetcode/search_in_rotated_sorted_array/playground.ipynb @@ -0,0 +1,61 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "9b04ddb0", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_search, run_search\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "72a31fc2", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "nums = [4, 5, 6, 7, 0, 1, 2]\n", + "target = 0\n", + "expected = 4" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d967f5a7", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_search(Solution, nums, target)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5d31022d", + "metadata": {}, + "outputs": [], + "source": [ + "assert_search(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/serialize_and_deserialize_binary_tree/playground.ipynb b/leetcode/serialize_and_deserialize_binary_tree/playground.ipynb new file mode 100644 index 0000000..5a79e9c --- /dev/null +++ b/leetcode/serialize_and_deserialize_binary_tree/playground.ipynb @@ -0,0 +1,59 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "9af03639", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_serialize_deserialize, run_serialize_deserialize\n", + "from solution import Codec" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9b6df939", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "root_list = [1, 2, 3, None, None, 4, 5]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a948da28", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_serialize_deserialize(Codec, root_list)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b05d43cf", + "metadata": {}, + "outputs": [], + "source": [ + "assert_serialize_deserialize(result, root_list)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/set_matrix_zeroes/playground.ipynb b/leetcode/set_matrix_zeroes/playground.ipynb new file mode 100644 index 0000000..c37ec1e --- /dev/null +++ b/leetcode/set_matrix_zeroes/playground.ipynb @@ -0,0 +1,57 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "97c5eb62", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_set_zeroes, run_set_zeroes\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2beda22a", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "matrix = [[1, 1, 1], [1, 0, 1], [1, 1, 1]]\n", + "expected = [[1, 0, 1], [0, 0, 0], [1, 0, 1]]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2c6eb1b8", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_set_zeroes(Solution, matrix)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "dec26219", + "metadata": {}, + "outputs": [], + "source": [ + "assert_set_zeroes(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/sort_colors/playground.ipynb b/leetcode/sort_colors/playground.ipynb new file mode 100644 index 0000000..70b54a6 --- /dev/null +++ b/leetcode/sort_colors/playground.ipynb @@ -0,0 +1,60 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "42df01e9", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_sort_colors, run_sort_colors\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cb71c976", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "nums = [2, 0, 2, 1, 1, 0]\n", + "expected = [0, 0, 1, 1, 2, 2]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3be9c5be", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_sort_colors(Solution, nums)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e27a8f35", + "metadata": {}, + "outputs": [], + "source": [ + "assert_sort_colors(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/spiral_matrix/playground.ipynb b/leetcode/spiral_matrix/playground.ipynb new file mode 100644 index 0000000..dcd809c --- /dev/null +++ b/leetcode/spiral_matrix/playground.ipynb @@ -0,0 +1,60 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "c1af4e8d", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_spiral_order, run_spiral_order\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "01a460c7", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]\n", + "expected = [1, 2, 3, 6, 9, 8, 7, 4, 5]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d957b7ce", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_spiral_order(Solution, matrix)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "994e5a65", + "metadata": {}, + "outputs": [], + "source": [ + "assert_spiral_order(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/string_to_integer_atoi/playground.ipynb b/leetcode/string_to_integer_atoi/playground.ipynb new file mode 100644 index 0000000..151e4fe --- /dev/null +++ b/leetcode/string_to_integer_atoi/playground.ipynb @@ -0,0 +1,60 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "d7f9ea1e", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_my_atoi, run_my_atoi\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f1ba60b5", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "s = \"42\"\n", + "expected = 42" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "191be9dd", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_my_atoi(Solution, s)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f7b64ab1", + "metadata": {}, + "outputs": [], + "source": [ + "assert_my_atoi(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/subsets/playground.ipynb b/leetcode/subsets/playground.ipynb new file mode 100644 index 0000000..c2b5928 --- /dev/null +++ b/leetcode/subsets/playground.ipynb @@ -0,0 +1,57 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "b33fce2b", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_subsets, run_subsets\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c218513c", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "nums = [1, 2, 3]\n", + "expected = [[], [1], [2], [1, 2], [3], [1, 3], [2, 3], [1, 2, 3]]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3aadeab3", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_subsets(Solution, nums)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "be104383", + "metadata": {}, + "outputs": [], + "source": [ + "assert_subsets(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/subtree_of_another_tree/playground.ipynb b/leetcode/subtree_of_another_tree/playground.ipynb new file mode 100644 index 0000000..96a2cd9 --- /dev/null +++ b/leetcode/subtree_of_another_tree/playground.ipynb @@ -0,0 +1,58 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "df964138", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_is_subtree, run_is_subtree\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "80f57a00", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "root_list: list[int | None] = [3, 4, 5, 1, 2]\n", + "sub_root_list: list[int | None] = [4, 1, 2]\n", + "expected = True" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "67499b7e", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_is_subtree(Solution, root_list, sub_root_list)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c0548199", + "metadata": {}, + "outputs": [], + "source": [ + "assert_is_subtree(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/sum_of_two_integers/playground.ipynb b/leetcode/sum_of_two_integers/playground.ipynb new file mode 100644 index 0000000..b9a6f84 --- /dev/null +++ b/leetcode/sum_of_two_integers/playground.ipynb @@ -0,0 +1,58 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "0d1de553", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_get_sum, run_get_sum\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d06b7a67", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "a = 1\n", + "b = 2\n", + "expected = 3" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "710270d3", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_get_sum(Solution, a, b)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ebc51f09", + "metadata": {}, + "outputs": [], + "source": [ + "assert_get_sum(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/swap_nodes_in_pairs/playground.ipynb b/leetcode/swap_nodes_in_pairs/playground.ipynb new file mode 100644 index 0000000..782ba40 --- /dev/null +++ b/leetcode/swap_nodes_in_pairs/playground.ipynb @@ -0,0 +1,57 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "c27e1829", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_swap_pairs, run_swap_pairs\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "30c0a49e", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "head_list = [1, 2, 3, 4]\n", + "expected = [2, 1, 4, 3]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3706da4f", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_swap_pairs(Solution, head_list)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9a0d0f98", + "metadata": {}, + "outputs": [], + "source": [ + "assert_swap_pairs(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/task_scheduler/playground.ipynb b/leetcode/task_scheduler/playground.ipynb new file mode 100644 index 0000000..f4e82e0 --- /dev/null +++ b/leetcode/task_scheduler/playground.ipynb @@ -0,0 +1,61 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "bb3c6044", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_least_interval, run_least_interval\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "bfe16107", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "tasks = [\"A\", \"A\", \"A\", \"B\", \"B\", \"B\"]\n", + "n = 2\n", + "expected = 8" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1e31eb44", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_least_interval(Solution, tasks, n)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9511caed", + "metadata": {}, + "outputs": [], + "source": [ + "assert_least_interval(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/three_sum/playground.ipynb b/leetcode/three_sum/playground.ipynb new file mode 100644 index 0000000..4af2484 --- /dev/null +++ b/leetcode/three_sum/playground.ipynb @@ -0,0 +1,60 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "18788709", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_three_sum, run_three_sum\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e0b521d2", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "nums = [-1, 0, 1, 2, -1, -4]\n", + "expected = [[-1, -1, 2], [-1, 0, 1]]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d6356af2", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_three_sum(Solution, nums)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "06968500", + "metadata": {}, + "outputs": [], + "source": [ + "assert_three_sum(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/time_based_key_value_store/playground.ipynb b/leetcode/time_based_key_value_store/playground.ipynb new file mode 100644 index 0000000..0dd3a65 --- /dev/null +++ b/leetcode/time_based_key_value_store/playground.ipynb @@ -0,0 +1,61 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "94ccc875", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_time_map_operations, run_time_map_operations\n", + "from solution import TimeMap" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ec0e79c9", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "operations = [\"TimeMap\", \"set\", \"get\", \"get\", \"set\", \"get\", \"get\"]\n", + "inputs = [[], [\"foo\", \"bar\", 1], [\"foo\", 1], [\"foo\", 3], [\"foo\", \"bar2\", 4], [\"foo\", 4], [\"foo\", 5]]\n", + "expected = [None, None, \"bar\", \"bar\", None, \"bar2\", \"bar2\"]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "92015f25", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_time_map_operations(TimeMap, operations, inputs)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d3e2e921", + "metadata": {}, + "outputs": [], + "source": [ + "assert_time_map_operations(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/top_k_frequent_elements/playground.ipynb b/leetcode/top_k_frequent_elements/playground.ipynb new file mode 100644 index 0000000..cdbc58a --- /dev/null +++ b/leetcode/top_k_frequent_elements/playground.ipynb @@ -0,0 +1,58 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "1fb80fea", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_top_k_frequent, run_top_k_frequent\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c56929c1", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "nums = [1, 1, 1, 2, 2, 3]\n", + "k = 2\n", + "expected = [1, 2]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9250126e", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_top_k_frequent(Solution, nums, k)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6e292480", + "metadata": {}, + "outputs": [], + "source": [ + "assert_top_k_frequent(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/top_k_frequent_words/playground.ipynb b/leetcode/top_k_frequent_words/playground.ipynb new file mode 100644 index 0000000..124a149 --- /dev/null +++ b/leetcode/top_k_frequent_words/playground.ipynb @@ -0,0 +1,58 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "a28b26d8", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_top_k_frequent, run_top_k_frequent\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4c38dc2b", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "words: list[str] = [\"i\", \"love\", \"leetcode\", \"i\", \"love\", \"coding\"]\n", + "k = 2\n", + "expected: list[str] = [\"i\", \"love\"]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9678bb49", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_top_k_frequent(Solution, words, k)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0358bd16", + "metadata": {}, + "outputs": [], + "source": [ + "assert_top_k_frequent(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/trapping_rain_water/playground.ipynb b/leetcode/trapping_rain_water/playground.ipynb new file mode 100644 index 0000000..04af681 --- /dev/null +++ b/leetcode/trapping_rain_water/playground.ipynb @@ -0,0 +1,60 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "2c04e6ef", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_trap, run_trap\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fee0be93", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "height = [0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1]\n", + "expected = 6" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "73aa6382", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_trap(Solution, height)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "be5049b8", + "metadata": {}, + "outputs": [], + "source": [ + "assert_trap(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/two_sum/playground.ipynb b/leetcode/two_sum/playground.ipynb new file mode 100644 index 0000000..c52dca7 --- /dev/null +++ b/leetcode/two_sum/playground.ipynb @@ -0,0 +1,61 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "a708098a", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_two_sum, run_two_sum\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e08b7e51", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "nums = [2, 7, 11, 15]\n", + "target = 9\n", + "expected = [0, 1]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "703c7e5b", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_two_sum(Solution, nums, target)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e5e269a7", + "metadata": {}, + "outputs": [], + "source": [ + "assert_two_sum(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/unique_paths/playground.ipynb b/leetcode/unique_paths/playground.ipynb new file mode 100644 index 0000000..817d8ef --- /dev/null +++ b/leetcode/unique_paths/playground.ipynb @@ -0,0 +1,58 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "b8df623c", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_unique_paths, run_unique_paths\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "52572cb9", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "m = 3\n", + "n = 7\n", + "expected = 28" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c744262f", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_unique_paths(Solution, m, n)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "76d19a1f", + "metadata": {}, + "outputs": [], + "source": [ + "assert_unique_paths(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/valid_anagram/playground.ipynb b/leetcode/valid_anagram/playground.ipynb new file mode 100644 index 0000000..77c8208 --- /dev/null +++ b/leetcode/valid_anagram/playground.ipynb @@ -0,0 +1,61 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "1706a133", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_is_anagram, run_is_anagram\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f6ab2584", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "s = \"anagram\"\n", + "t = \"nagaram\"\n", + "expected = True" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "97e8aae5", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_is_anagram(Solution, s, t)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "94030061", + "metadata": {}, + "outputs": [], + "source": [ + "assert_is_anagram(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/valid_palindrome/playground.ipynb b/leetcode/valid_palindrome/playground.ipynb new file mode 100644 index 0000000..6c5d1fb --- /dev/null +++ b/leetcode/valid_palindrome/playground.ipynb @@ -0,0 +1,60 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "54f77629", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_is_palindrome, run_is_palindrome\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ef3d32f2", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "s = \"A man, a plan, a canal: Panama\"\n", + "expected = True" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "817d49be", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_is_palindrome(Solution, s)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "93789f9b", + "metadata": {}, + "outputs": [], + "source": [ + "assert_is_palindrome(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/valid_parentheses/playground.ipynb b/leetcode/valid_parentheses/playground.ipynb new file mode 100644 index 0000000..12a318b --- /dev/null +++ b/leetcode/valid_parentheses/playground.ipynb @@ -0,0 +1,60 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "f242b332", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_is_valid, run_is_valid\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "63416d95", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "s = \"()\"\n", + "expected = True" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "73d8af9f", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_is_valid(Solution, s)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fee9b7a2", + "metadata": {}, + "outputs": [], + "source": [ + "assert_is_valid(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/valid_sudoku/playground.ipynb b/leetcode/valid_sudoku/playground.ipynb new file mode 100644 index 0000000..33a7732 --- /dev/null +++ b/leetcode/valid_sudoku/playground.ipynb @@ -0,0 +1,67 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "b0237493", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_is_valid_sudoku, run_is_valid_sudoku\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b79d778c", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "board = [\n", + " [\"5\", \"3\", \".\", \".\", \"7\", \".\", \".\", \".\", \".\"],\n", + " [\"6\", \".\", \".\", \"1\", \"9\", \"5\", \".\", \".\", \".\"],\n", + " [\".\", \"9\", \"8\", \".\", \".\", \".\", \".\", \"6\", \".\"],\n", + " [\"8\", \".\", \".\", \".\", \"6\", \".\", \".\", \".\", \"3\"],\n", + " [\"4\", \".\", \".\", \"8\", \".\", \"3\", \".\", \".\", \"1\"],\n", + " [\"7\", \".\", \".\", \".\", \"2\", \".\", \".\", \".\", \"6\"],\n", + " [\".\", \"6\", \".\", \".\", \".\", \".\", \"2\", \"8\", \".\"],\n", + " [\".\", \".\", \".\", \"4\", \"1\", \"9\", \".\", \".\", \"5\"],\n", + " [\".\", \".\", \".\", \".\", \".\", \".\", \".\", \"7\", \"9\"],\n", + "]\n", + "expected = True" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c8214835", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_is_valid_sudoku(Solution, board)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b942688b", + "metadata": {}, + "outputs": [], + "source": [ + "assert_is_valid_sudoku(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/validate_binary_search_tree/playground.ipynb b/leetcode/validate_binary_search_tree/playground.ipynb new file mode 100644 index 0000000..df3bb37 --- /dev/null +++ b/leetcode/validate_binary_search_tree/playground.ipynb @@ -0,0 +1,60 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "6628a343", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_is_valid_bst, run_is_valid_bst\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f4b19e5e", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "root_list = [2, 1, 3]\n", + "expected = True" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "66a23c20", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_is_valid_bst(Solution, root_list)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "602ffe83", + "metadata": {}, + "outputs": [], + "source": [ + "assert_is_valid_bst(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/word_break/playground.ipynb b/leetcode/word_break/playground.ipynb new file mode 100644 index 0000000..6c00e1e --- /dev/null +++ b/leetcode/word_break/playground.ipynb @@ -0,0 +1,61 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "e7ae47d2", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_word_break, run_word_break\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e4817d59", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "s = \"leetcode\"\n", + "word_dict = [\"leet\", \"code\"]\n", + "expected = True" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b78888fd", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_word_break(Solution, s, word_dict)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8242ad20", + "metadata": {}, + "outputs": [], + "source": [ + "assert_word_break(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/word_ladder/playground.ipynb b/leetcode/word_ladder/playground.ipynb new file mode 100644 index 0000000..4779245 --- /dev/null +++ b/leetcode/word_ladder/playground.ipynb @@ -0,0 +1,62 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "a2984eb3", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_ladder_length, run_ladder_length\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "963504ec", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "begin_word = \"hit\"\n", + "end_word = \"cog\"\n", + "word_list = [\"hot\", \"dot\", \"dog\", \"lot\", \"log\", \"cog\"]\n", + "expected = 5" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "61971591", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_ladder_length(Solution, begin_word, end_word, word_list)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8daa05da", + "metadata": {}, + "outputs": [], + "source": [ + "assert_ladder_length(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/word_search/playground.ipynb b/leetcode/word_search/playground.ipynb new file mode 100644 index 0000000..7406dda --- /dev/null +++ b/leetcode/word_search/playground.ipynb @@ -0,0 +1,58 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "e30dbcd1", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_exist, run_exist\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "55e617fa", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "board = [[\"A\", \"B\", \"C\", \"E\"], [\"S\", \"F\", \"C\", \"S\"], [\"A\", \"D\", \"E\", \"E\"]]\n", + "word = \"ABCCED\"\n", + "expected = True" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "762a288c", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_exist(Solution, board, word)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "acc32e51", + "metadata": {}, + "outputs": [], + "source": [ + "assert_exist(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/word_search_ii/playground.ipynb b/leetcode/word_search_ii/playground.ipynb new file mode 100644 index 0000000..c15fdcb --- /dev/null +++ b/leetcode/word_search_ii/playground.ipynb @@ -0,0 +1,58 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "f760845a", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_find_words, run_find_words\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "dd10580f", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "board = [[\"o\", \"a\", \"a\", \"n\"], [\"e\", \"t\", \"a\", \"e\"], [\"i\", \"h\", \"k\", \"r\"], [\"i\", \"f\", \"l\", \"v\"]]\n", + "words = [\"oath\", \"pea\", \"eat\", \"rain\"]\n", + "expected = [\"eat\", \"oath\"]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d30f5298", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_find_words(Solution, board, words)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fc116200", + "metadata": {}, + "outputs": [], + "source": [ + "assert_find_words(result, expected)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/leetcode/zero_one_matrix/playground.ipynb b/leetcode/zero_one_matrix/playground.ipynb new file mode 100644 index 0000000..477c649 --- /dev/null +++ b/leetcode/zero_one_matrix/playground.ipynb @@ -0,0 +1,60 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "d2a7f8d5", + "metadata": {}, + "outputs": [], + "source": [ + "from helpers import assert_update_matrix, run_update_matrix\n", + "from solution import Solution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5f67fd33", + "metadata": {}, + "outputs": [], + "source": [ + "# Example test case\n", + "mat = [[0, 0, 0], [0, 1, 0], [1, 1, 1]]\n", + "expected = [[0, 0, 0], [0, 1, 0], [1, 2, 1]]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "efc3bfc6", + "metadata": {}, + "outputs": [], + "source": [ + "result = run_update_matrix(Solution, mat)\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b97f06e0", + "metadata": {}, + "outputs": [], + "source": [ + "assert_update_matrix(result, expected)" + ] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "leetcode-py-py3.13", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}