Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
4d81400
feat: add lowest_common_ancestor_of_a_binary_tree
wisarootl Sep 6, 2025
32e2f2c
feat: update dict tree
wisarootl Sep 6, 2025
93834e5
feat: add word ladder
wisarootl Sep 6, 2025
d40fce4
feat: add Serialize and Deserialize Binary Tree
wisarootl Sep 6, 2025
19374dc
feat: add find_median_from_data_stream
wisarootl Sep 6, 2025
7eff232
feat: add Basic Calculator
wisarootl Sep 6, 2025
ad6325c
feat: add Merge k Sorted Lists
wisarootl Sep 6, 2025
e586905
feat: add DoublyListNode
wisarootl Sep 6, 2025
5b27fa9
feat: add Ransom Note
wisarootl Sep 6, 2025
f0a2a39
feat: add First Bad Version
wisarootl Sep 6, 2025
49412c3
feat: Climbing Stairs
wisarootl Sep 6, 2025
a93e761
feat: add Majority Element
wisarootl Sep 6, 2025
1e31975
feat: add Diameter of Binary Tree
wisarootl Sep 6, 2025
63dce89
feat: add Middle of the Linked List
wisarootl Sep 6, 2025
a7ad8ba
feat: add Contains Duplicate
wisarootl Sep 6, 2025
6d4d393
feat: add Flood Fill
wisarootl Sep 6, 2025
bd6d987
feat: add Valid Parentheses
wisarootl Sep 6, 2025
8f83609
feat: add Balanced Binary Tree
wisarootl Sep 6, 2025
0ed0402
feat: add Merge Two Sorted Lists
wisarootl Sep 6, 2025
76581dc
feat: add Best Time to Buy and Sell Stock
wisarootl Sep 6, 2025
a99f4c4
feat: add Implement Queue using Stacks
wisarootl Sep 6, 2025
197c64b
feat: add 01 Matrix
wisarootl Sep 6, 2025
d73819b
feat: add Course Schedule
wisarootl Sep 7, 2025
b422baf
feat: add Rotting Oranges
wisarootl Sep 7, 2025
61ef1f6
feat: add Permutations
wisarootl Sep 7, 2025
96908f2
feat: add Word Break
wisarootl Sep 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions .templates/leetcode/json/balanced_binary_tree.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"problem_name": "balanced_binary_tree",
"solution_class_name": "Solution",
"problem_number": "110",
"problem_title": "Balanced Binary Tree",
"difficulty": "Easy",
"topics": "Tree, Depth-First Search, Binary Tree",
"tags": ["grind-75"],
"readme_description": "Given a binary tree, determine if it is **height-balanced**.\n\nA height-balanced binary tree is a binary tree in which the depth of the two subtrees of every node never differs by more than one.",
"readme_examples": [
{
"content": "![Example 1](https://assets.leetcode.com/uploads/2020/10/06/balance_1.jpg)\n\n```\nInput: root = [3,9,20,null,null,15,7]\nOutput: true\n```"
},
{
"content": "![Example 2](https://assets.leetcode.com/uploads/2020/10/06/balance_2.jpg)\n\n```\nInput: root = [1,2,2,3,3,null,null,4,4]\nOutput: false\n```"
},
{ "content": "```\nInput: root = []\nOutput: true\n```" }
],
"readme_constraints": "- The number of nodes in the tree is in the range `[0, 5000]`.\n- `-10^4 <= Node.val <= 10^4`",
"readme_additional": "",
"solution_imports": "from leetcode_py import TreeNode",
"solution_methods": [
{
"name": "is_balanced",
"parameters": "root: TreeNode | None",
"return_type": "bool",
"dummy_return": "False"
}
],
"test_imports": "import pytest\nfrom leetcode_py.test_utils import logged_test\nfrom leetcode_py import TreeNode\nfrom .solution import Solution",
"test_class_name": "BalancedBinaryTree",
"test_helper_methods": [
{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }
],
"test_methods": [
{
"name": "test_is_balanced",
"parametrize": "root_list, expected",
"parametrize_typed": "root_list: list[int | None], expected: bool",
"test_cases": "[([3, 9, 20, None, None, 15, 7], True), ([1, 2, 2, 3, 3, None, None, 4, 4], False), ([], True)]",
"body": "root = TreeNode.from_list(root_list)\nresult = self.solution.is_balanced(root)\nassert result == expected"
}
],
"playground_imports": "from solution import Solution\nfrom leetcode_py import TreeNode",
"playground_test_case": "# Example test case\nroot_list = [3, 9, 20, None, None, 15, 7]\nroot = TreeNode.from_list(root_list)\nexpected = True",
"playground_execution": "result = Solution().is_balanced(root)\nresult",
"playground_assertion": "assert result == expected"
}
39 changes: 39 additions & 0 deletions .templates/leetcode/json/basic_calculator.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"problem_name": "basic_calculator",
"solution_class_name": "Solution",
"problem_number": "224",
"problem_title": "Basic Calculator",
"difficulty": "Hard",
"topics": "Math, String, Stack, Recursion",
"tags": ["grind-75"],
"readme_description": "Given a string `s` representing a valid expression, implement a basic calculator to evaluate it, and return the result of the evaluation.\n\n**Note:** You are **not** allowed to use any built-in function which evaluates strings as mathematical expressions, such as `eval()`.",
"readme_examples": [
{ "content": "```\nInput: s = \"1 + 1\"\nOutput: 2\n```" },
{ "content": "```\nInput: s = \" 2-1 + 2 \"\nOutput: 3\n```" },
{ "content": "```\nInput: s = \"(1+(4+5+2)-3)+(6+8)\"\nOutput: 23\n```" }
],
"readme_constraints": "- `1 <= s.length <= 3 * 10^5`\n- `s` consists of digits, `'+'`, `'-'`, `'('`, `')'`, and `' '`.\n- `s` represents a valid expression.\n- `'+'` is **not** used as a unary operation (i.e., `\"+1\"` and `\"+(2 + 3)\"` is invalid).\n- `'-'` could be used as a unary operation (i.e., `\"-1\"` and `\"-(2 + 3)\"` is valid).\n- There will be no two consecutive operators in the input.\n- Every number and running calculation will fit in a signed 32-bit integer.",
"readme_additional": "",
"solution_imports": "",
"solution_methods": [
{ "name": "calculate", "parameters": "s: str", "return_type": "int", "dummy_return": "0" }
],
"test_imports": "import pytest\nfrom leetcode_py.test_utils import logged_test\nfrom .solution import Solution",
"test_class_name": "BasicCalculator",
"test_helper_methods": [
{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }
],
"test_methods": [
{
"name": "test_calculate",
"parametrize": "s, expected",
"parametrize_typed": "s: str, expected: int",
"test_cases": "[(\"1 + 1\", 2), (\" 2-1 + 2 \", 3), (\"(1+(4+5+2)-3)+(6+8)\", 23), (\"1\", 1), (\"-1\", -1), (\"-(1+2)\", -3), (\"2147483647\", 2147483647), (\"1-1+1\", 1)]",
"body": "result = self.solution.calculate(s)\nassert result == expected"
}
],
"playground_imports": "from solution import Solution",
"playground_test_case": "# Example test case\ns = '(1+(4+5+2)-3)+(6+8)'\nexpected = 23",
"playground_execution": "result = Solution().calculate(s)\nresult",
"playground_assertion": "assert result == expected"
}
47 changes: 47 additions & 0 deletions .templates/leetcode/json/best_time_to_buy_and_sell_stock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"problem_name": "best_time_to_buy_and_sell_stock",
"solution_class_name": "Solution",
"problem_number": "121",
"problem_title": "Best Time to Buy and Sell Stock",
"difficulty": "Easy",
"topics": "Array, Dynamic Programming",
"tags": ["grind-75"],
"readme_description": "You are given an array `prices` where `prices[i]` is the price of a given stock on the ith day.\n\nYou want to maximize your profit by choosing a **single day** to buy one stock and choosing a **different day in the future** to sell that stock.\n\nReturn *the maximum profit you can achieve from this transaction*. If you cannot achieve any profit, return `0`.",
"readme_examples": [
{
"content": "```\nInput: prices = [7,1,5,3,6,4]\nOutput: 5\n```\n**Explanation:** Buy on day 2 (price = 1) and sell on day 5 (price = 6), profit = 6-1 = 5.\nNote that buying on day 2 and selling on day 1 is not allowed because you must buy before you sell."
},
{
"content": "```\nInput: prices = [7,6,4,3,1]\nOutput: 0\n```\n**Explanation:** In this case, no transactions are done and the max profit = 0."
}
],
"readme_constraints": "- 1 <= prices.length <= 10^5\n- 0 <= prices[i] <= 10^4",
"readme_additional": "",
"solution_imports": "",
"solution_methods": [
{
"name": "max_profit",
"parameters": "prices: list[int]",
"return_type": "int",
"dummy_return": "0"
}
],
"test_imports": "import pytest\nfrom leetcode_py.test_utils import logged_test\nfrom .solution import Solution",
"test_class_name": "BestTimeToBuyAndSellStock",
"test_helper_methods": [
{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }
],
"test_methods": [
{
"name": "test_max_profit",
"parametrize": "prices, expected",
"parametrize_typed": "prices: list[int], expected: int",
"test_cases": "[([7, 1, 5, 3, 6, 4], 5), ([7, 6, 4, 3, 1], 0), ([1, 2, 3, 4, 5], 4), ([5, 4, 3, 2, 1], 0), ([1], 0), ([2, 1], 0), ([1, 2], 1), ([3, 2, 6, 5, 0, 3], 4)]",
"body": "result = self.solution.max_profit(prices)\nassert result == expected"
}
],
"playground_imports": "from solution import Solution",
"playground_test_case": "# Example test case\nprices = [7, 1, 5, 3, 6, 4]\nexpected = 5",
"playground_execution": "result = Solution().max_profit(prices)\nresult",
"playground_assertion": "assert result == expected"
}
46 changes: 46 additions & 0 deletions .templates/leetcode/json/binary_tree_level_order_traversal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"problem_name": "binary_tree_level_order_traversal",
"solution_class_name": "Solution",
"problem_number": "102",
"problem_title": "Binary Tree Level Order Traversal",
"difficulty": "Medium",
"topics": "Tree, Breadth-First Search, Binary Tree",
"tags": ["grind-75"],
"readme_description": "Given the `root` of a binary tree, return the level order traversal of its nodes' values. (i.e., from left to right, level by level).",
"readme_examples": [
{
"content": "![Example 1](https://assets.leetcode.com/uploads/2021/02/19/tree1.jpg)\n\n```\nInput: root = [3,9,20,null,null,15,7]\nOutput: [[3],[9,20],[15,7]]\n```"
},
{ "content": "```\nInput: root = [1]\nOutput: [[1]]\n```" },
{ "content": "```\nInput: root = []\nOutput: []\n```" }
],
"readme_constraints": "- The number of nodes in the tree is in the range [0, 2000]\n- -1000 <= Node.val <= 1000",
"readme_additional": "",
"solution_imports": "from leetcode_py import TreeNode",
"solution_methods": [
{
"name": "level_order",
"parameters": "root: TreeNode | None",
"return_type": "list[list[int]]",
"dummy_return": "[]"
}
],
"test_imports": "import pytest\nfrom leetcode_py.test_utils import logged_test\nfrom leetcode_py import TreeNode\nfrom .solution import Solution",
"test_class_name": "BinaryTreeLevelOrderTraversal",
"test_helper_methods": [
{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }
],
"test_methods": [
{
"name": "test_level_order",
"parametrize": "root_list, expected",
"parametrize_typed": "root_list: list[int | None], expected: list[list[int]]",
"test_cases": "[([3, 9, 20, None, None, 15, 7], [[3], [9, 20], [15, 7]]), ([1], [[1]]), ([], []), ([1, 2, 3, 4, 5, 6, 7], [[1], [2, 3], [4, 5, 6, 7]]), ([1, 2, None, 3, None, 4, None, 5], [[1], [2], [3], [4], [5]])]",
"body": "root = TreeNode.from_list(root_list) if root_list else None\nresult = self.solution.level_order(root)\nassert result == expected"
}
],
"playground_imports": "from solution import Solution\nfrom leetcode_py import TreeNode",
"playground_test_case": "# Example test case\nroot_list = [3, 9, 20, None, None, 15, 7]\nroot = TreeNode.from_list(root_list)\nexpected = [[3], [9, 20], [15, 7]]",
"playground_execution": "result = Solution().level_order(root)\nresult",
"playground_assertion": "assert result == expected"
}
42 changes: 42 additions & 0 deletions .templates/leetcode/json/climbing_stairs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"problem_name": "climbing_stairs",
"solution_class_name": "Solution",
"problem_number": "70",
"problem_title": "Climbing Stairs",
"difficulty": "Easy",
"topics": "Math, Dynamic Programming, Memoization",
"tags": ["grind-75"],
"readme_description": "You are climbing a staircase. It takes `n` steps to reach the top.\n\nEach time you can either climb `1` or `2` steps. In how many distinct ways can you climb to the top?",
"readme_examples": [
{
"content": "```\nInput: n = 2\nOutput: 2\n```\n**Explanation:** There are two ways to climb to the top.\n1. 1 step + 1 step\n2. 2 steps"
},
{
"content": "```\nInput: n = 3\nOutput: 3\n```\n**Explanation:** There are three ways to climb to the top.\n1. 1 step + 1 step + 1 step\n2. 1 step + 2 steps\n3. 2 steps + 1 step"
}
],
"readme_constraints": "- 1 <= n <= 45",
"readme_additional": "",
"solution_imports": "",
"solution_methods": [
{ "name": "climb_stairs", "parameters": "n: int", "return_type": "int", "dummy_return": "1" }
],
"test_imports": "import pytest\nfrom leetcode_py.test_utils import logged_test\nfrom .solution import Solution",
"test_class_name": "ClimbingStairs",
"test_helper_methods": [
{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }
],
"test_methods": [
{
"name": "test_climb_stairs",
"parametrize": "n, expected",
"parametrize_typed": "n: int, expected: int",
"test_cases": "[(1, 1), (2, 2), (3, 3), (4, 5), (5, 8), (6, 13), (10, 89), (20, 10946), (45, 1836311903)]",
"body": "result = self.solution.climb_stairs(n)\nassert result == expected"
}
],
"playground_imports": "from solution import Solution",
"playground_test_case": "# Example test case\nn = 3\nexpected = 3",
"playground_execution": "result = Solution().climb_stairs(n)\nresult",
"playground_assertion": "assert result == expected"
}
48 changes: 48 additions & 0 deletions .templates/leetcode/json/combination_sum.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"problem_name": "combination_sum",
"solution_class_name": "Solution",
"problem_number": "39",
"problem_title": "Combination Sum",
"difficulty": "Medium",
"topics": "Array, Backtracking",
"tags": ["grind-75"],
"readme_description": "Given an array of **distinct** integers `candidates` and a target integer `target`, return *a list of all **unique combinations** of* `candidates` *where the chosen numbers sum to* `target`. You may return the combinations in **any order**.\n\nThe **same** number may be chosen from `candidates` an **unlimited number of times**. Two combinations are unique if the frequency of at least one of the chosen numbers is different.\n\nThe test cases are generated such that the number of unique combinations that sum up to `target` is less than `150` combinations for the given input.",
"readme_examples": [
{
"content": "```\nInput: candidates = [2,3,6,7], target = 7\nOutput: [[2,2,3],[7]]\n```\n**Explanation:** 2 and 3 are candidates, and 2 + 2 + 3 = 7. Note that 2 can be used multiple times. 7 is a candidate, and 7 = 7. These are the only two combinations."
},
{
"content": "```\nInput: candidates = [2,3,5], target = 8\nOutput: [[2,2,2,2],[2,3,3],[3,5]]\n```"
},
{ "content": "```\nInput: candidates = [2], target = 1\nOutput: []\n```" }
],
"readme_constraints": "- 1 <= candidates.length <= 30\n- 2 <= candidates[i] <= 40\n- All elements of candidates are distinct.\n- 1 <= target <= 40",
"readme_additional": "",
"solution_imports": "",
"solution_methods": [
{
"name": "combination_sum",
"parameters": "candidates: list[int], target: int",
"return_type": "list[list[int]]",
"dummy_return": "[]"
}
],
"test_imports": "import pytest\nfrom leetcode_py.test_utils import logged_test\nfrom .solution import Solution",
"test_class_name": "CombinationSum",
"test_helper_methods": [
{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }
],
"test_methods": [
{
"name": "test_combination_sum",
"parametrize": "candidates, target, expected",
"parametrize_typed": "candidates: list[int], target: int, expected: list[list[int]]",
"test_cases": "[([2, 3, 6, 7], 7, [[2, 2, 3], [7]]), ([2, 3, 5], 8, [[2, 2, 2, 2], [2, 3, 3], [3, 5]]), ([2], 1, [])]",
"body": "result = self.solution.combination_sum(candidates, target)\n# Sort both result and expected for comparison\nresult_sorted = [sorted(combo) for combo in result]\nexpected_sorted = [sorted(combo) for combo in expected]\nresult_sorted.sort()\nexpected_sorted.sort()\nassert result_sorted == expected_sorted"
}
],
"playground_imports": "from solution import Solution",
"playground_test_case": "# Example test case\ncandidates = [2, 3, 6, 7]\ntarget = 7\nexpected = [[2, 2, 3], [7]]",
"playground_execution": "result = Solution().combination_sum(candidates, target)\nresult",
"playground_assertion": "# Sort for comparison\nresult_sorted = [sorted(combo) for combo in result]\nexpected_sorted = [sorted(combo) for combo in expected]\nresult_sorted.sort()\nexpected_sorted.sort()\nassert result_sorted == expected_sorted"
}
48 changes: 48 additions & 0 deletions .templates/leetcode/json/contains_duplicate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"problem_name": "contains_duplicate",
"solution_class_name": "Solution",
"problem_number": "217",
"problem_title": "Contains Duplicate",
"difficulty": "Easy",
"topics": "Array, Hash Table, Sorting",
"tags": ["grind-75"],
"readme_description": "Given an integer array `nums`, return `true` if any value appears **at least twice** in the array, and return `false` if every element is distinct.",
"readme_examples": [
{
"content": "```\nInput: nums = [1,2,3,1]\nOutput: true\n```\n**Explanation:** The element 1 occurs at the indices 0 and 3."
},
{
"content": "```\nInput: nums = [1,2,3,4]\nOutput: false\n```\n**Explanation:** All elements are distinct."
},
{ "content": "```\nInput: nums = [1,1,1,3,3,4,3,2,4,2]\nOutput: true\n```" }
],
"readme_constraints": "- 1 <= nums.length <= 10^5\n- -10^9 <= nums[i] <= 10^9",
"readme_additional": "",
"solution_imports": "",
"solution_methods": [
{
"name": "contains_duplicate",
"parameters": "nums: list[int]",
"return_type": "bool",
"dummy_return": "False"
}
],
"test_imports": "import pytest\nfrom leetcode_py.test_utils import logged_test\nfrom .solution import Solution",
"test_class_name": "ContainsDuplicate",
"test_helper_methods": [
{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }
],
"test_methods": [
{
"name": "test_contains_duplicate",
"parametrize": "nums, expected",
"parametrize_typed": "nums: list[int], expected: bool",
"test_cases": "[([1, 2, 3, 1], True), ([1, 2, 3, 4], False), ([1, 1, 1, 3, 3, 4, 3, 2, 4, 2], True)]",
"body": "result = self.solution.contains_duplicate(nums)\nassert result == expected"
}
],
"playground_imports": "from solution import Solution",
"playground_test_case": "# Example test case\nnums = [1, 2, 3, 1]\nexpected = True",
"playground_execution": "result = Solution().contains_duplicate(nums)\nresult",
"playground_assertion": "assert result == expected"
}
Loading
Loading