Skip to content

Commit cb574c6

Browse files
committed
feat: add more leetcode problems
1 parent 4f34eb8 commit cb574c6

38 files changed

+1321
-173
lines changed

.cursor/.dev/1-update-cookiecutter-test-template.md

Lines changed: 0 additions & 166 deletions
This file was deleted.

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
PYTHON_VERSION = 3.13
2-
PROBLEM ?= palindromic_substrings
2+
PROBLEM ?= reverse_nodes_in_k_group
33
FORCE ?= 0
44
COMMA := ,
55

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ A Python package to generate professional LeetCode practice environments. Featur
4040

4141
**Current Problem Sets**:
4242

43-
- **grind-75** (75 problems) - Essential coding interview questions from [Grind 75](https://www.techinterviewhandbook.org/grind75/) ✅ Complete
44-
- **grind** (100+ problems) - Extended Grind collection including all Grind 75 plus additional problems 🚧 Partial
45-
- **blind-75** (75 problems) - Original [Blind 75](https://leetcode.com/problem-list/xi4ci4ig/) curated list 🚧 Partial
46-
- **neetcode-150** (150+ problems) - Comprehensive [NeetCode 150](https://neetcode.io/practice) problem set 🚧 Partial
47-
- **algo-master-75** (75 problems) - Curated algorithmic mastery problems 🚧 Partial
43+
- **grind-75** - Essential coding interview questions from [Grind 75](https://www.techinterviewhandbook.org/grind75/) ✅ Complete
44+
- **grind** - Extended Grind collection including all Grind 75 plus additional problems 🚧 Partial
45+
- **blind-75** - Original [Blind 75](https://leetcode.com/problem-list/xi4ci4ig/) curated list 🚧 Partial
46+
- **neetcode-150** - Comprehensive [NeetCode 150](https://neetcode.io/practice) problem set 🚧 Partial
47+
- **algo-master-75** - Curated algorithmic mastery problems 🚧 Partial
4848

49-
**Coverage**: 100+ unique problems across all major coding interview topics and difficulty levels.
49+
**Coverage**: 120+ unique problems across all major coding interview topics and difficulty levels.
5050

5151
**Note**: Some problem sets are partially covered. We're actively working to complete all collections. [Contributions welcome!](https://github.com/wisarootl/leetcode-py/blob/main/CONTRIBUTING.md)
5252

leetcode/add_two_numbers/README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Add Two Numbers
2+
3+
**Difficulty:** Medium
4+
**Topics:** Linked List, Math, Recursion
5+
**Tags:** algo-master-75
6+
7+
**LeetCode:** [Problem 2](https://leetcode.com/problems/add-two-numbers/description/)
8+
9+
## Problem Description
10+
11+
You are given two **non-empty** linked lists representing two non-negative integers. The digits are stored in **reverse order**, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list.
12+
13+
You may assume the two numbers do not contain any leading zero, except the number 0 itself.
14+
15+
## Examples
16+
17+
### Example 1:
18+
19+
![Example 1](https://assets.leetcode.com/uploads/2020/10/02/addtwonumber1.jpg)
20+
21+
```
22+
Input: l1 = [2,4,3], l2 = [5,6,4]
23+
Output: [7,0,8]
24+
Explanation: 342 + 465 = 807.
25+
```
26+
27+
### Example 2:
28+
29+
```
30+
Input: l1 = [0], l2 = [0]
31+
Output: [0]
32+
```
33+
34+
### Example 3:
35+
36+
```
37+
Input: l1 = [9,9,9,9,9,9,9], l2 = [9,9,9,9]
38+
Output: [8,9,9,9,0,0,0,1]
39+
```
40+
41+
## Constraints
42+
43+
- The number of nodes in each linked list is in the range [1, 100].
44+
- 0 <= Node.val <= 9
45+
- It is guaranteed that the list represents a number that does not have leading zeros.

leetcode/add_two_numbers/__init__.py

Whitespace-only changes.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from leetcode_py import ListNode
2+
3+
4+
def run_add_two_numbers(solution_class: type, l1_vals: list[int], l2_vals: list[int]):
5+
l1 = ListNode.from_list(l1_vals)
6+
l2 = ListNode.from_list(l2_vals)
7+
implementation = solution_class()
8+
return implementation.add_two_numbers(l1, l2)
9+
10+
11+
def assert_add_two_numbers(result: ListNode[int] | None, expected_vals: list[int]) -> bool:
12+
expected = ListNode.from_list(expected_vals)
13+
assert result == expected
14+
return True
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# ---
2+
# jupyter:
3+
# jupytext:
4+
# text_representation:
5+
# extension: .py
6+
# format_name: percent
7+
# format_version: '1.3'
8+
# jupytext_version: 1.17.3
9+
# kernelspec:
10+
# display_name: leetcode-py-py3.13
11+
# language: python
12+
# name: python3
13+
# ---
14+
15+
# %%
16+
from helpers import assert_add_two_numbers, run_add_two_numbers
17+
from solution import Solution
18+
19+
# %%
20+
# Example test case
21+
l1_vals = [2, 4, 3]
22+
l2_vals = [5, 6, 4]
23+
expected_vals = [7, 0, 8]
24+
25+
# %%
26+
result = run_add_two_numbers(Solution, l1_vals, l2_vals)
27+
result
28+
29+
# %%
30+
assert_add_two_numbers(result, expected_vals)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from leetcode_py import ListNode
2+
3+
4+
class Solution:
5+
6+
# Time: O(max(m, n))
7+
# Space: O(max(m, n))
8+
def add_two_numbers(
9+
self, l1: ListNode[int] | None, l2: ListNode[int] | None
10+
) -> ListNode[int] | None:
11+
dummy = ListNode(0)
12+
current = dummy
13+
carry = 0
14+
15+
while l1 or l2 or carry:
16+
val1 = l1.val if l1 else 0
17+
val2 = l2.val if l2 else 0
18+
19+
total = val1 + val2 + carry
20+
carry = total // 10
21+
current.next = ListNode(total % 10)
22+
current = current.next
23+
24+
l1 = l1.next if l1 else None
25+
l2 = l2.next if l2 else None
26+
27+
return dummy.next

0 commit comments

Comments
 (0)