Skip to content

Commit 3dadf59

Browse files
committed
Update remaining files
1 parent 958f580 commit 3dadf59

109 files changed

Lines changed: 1008 additions & 1048 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.claude/settings.local.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"allow": [
44
"Bash(grep *)",
55
"Bash(ls *)",
6-
"Bash(just *)"
6+
"Bash(just *)",
7+
"Bash(uv run *)"
78
]
89
}
910
}

‎CLAUDE.md‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,19 @@ import via the top-level package name, e.g. `from algorithm_theory.binary_search
2626
Three categories of top-level directories, per the root `README.md`:
2727

2828
- **`algorithm_theory/`** — canonical/fundamental algorithm approaches (e.g. binary/jump/linear search, bubble
29-
sort). Explanations for these live as **module-level docstrings in the `.py` files themselves**, not in a
30-
README — this directory intentionally deviates from the pattern below.
29+
sort).
3130
- **`data_structures/`** — custom implementations of core data structures (binary tree, linked lists, queue,
3231
stack, trie) that other topic directories' problems build on top of.
3332
- **Topic/problem directories** (`arrays/`, `binary_search/`, `binary_tree/`, `circularly_linked_list/`,
3433
`doubly_linked_list/`, `integers/`, `math_problems/`, `multi_dimensional_arrays/`, `n_ary_tree/`, `queues/`,
35-
`singly_linked_lists/`, `stacks/`, `strings/`, `trie/`) — one function (or small set of related functions) per
36-
file solving a specific problem. Each of these directories has a `README.md` that duplicates the problem
37-
description and solution code inline as documentation (see any existing entry, e.g. `stacks/README.md`, as the
38-
template when adding a new problem/README section).
34+
`singly_linked_lists/`, `stacks/`, `strings/`, `trie/`)
35+
36+
The problem description, constraints, and examples live as a
37+
**doc comment directly on the function/class that solves it** (see any existing file, e.g.
38+
`arrays/two_sum.py`, as the template when adding a new problem). Only when a file genuinely has multiple
39+
top-level functions/classes for one problem (e.g. a brute-force and an optimized approach, like
40+
`stacks/daily_temperatures.py`) does it use a module-level docstring for the shared problem statement plus a
41+
short docstring per function for the approach-specific detail — a single-function file should never have both a module docstring and a redundant function docstring.
3942

4043
Tests live under `tests/<same-directory-name>/test_<module>.py`, mirroring the source layout 1:1 (e.g.
4144
`algorithm_theory/binary_search.py` → `tests/algorithm_theory/test_binary_search.py`). `test_helpers/test_helpers.py`

‎README.md‎

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,27 @@
33
Various Data Structures and Algorithm Solutions in Python (3.x). Succinct Python one-liners are avoided in most solutions
44
to prevent obscuring the function and logic of the algorithms / data-structures.
55

6-
* [Algorithm Theory](algorithm_theory/README.md)
7-
* [Searches](algorithm_theory/README.md#searches)
8-
* [Binary Search](algorithm_theory/README.md#binary-search)
9-
* [Jump Search](algorithm_theory/README.md#jump-search)
10-
* [Linear Search](algorithm_theory/README.md#linear-search)
11-
* [Sorts](algorithm_theory/README.md#sorts)
12-
* [Bubble Sort](algorithm_theory/README.md#bubble-sort)
13-
* [Data Structures](data_structures/README.md)
14-
* [Binary Tree](data_structures/README.md#binary-tree)
15-
* [Circularly Linked List](data_structures/README.md#circularly-linked-list)
16-
* [Doubly Linked List](data_structures/README.md#doubly-linked-list)
17-
* [Singly Linked List](data_structures/README.md#singly-linked-list)
18-
* [Queue](data_structures/README.md#queue)
19-
* [Stack](data_structures/README.md#stack)
20-
* [Trie](data_structures/README.md#trie)
6+
* [Algorithm Theory](algorithm_theory/)
7+
* [Data Structures](data_structures/)
218

229
## Algorithms
2310

24-
* [Arrays](arrays/README.md)
25-
* [Binary Search](binary_search/README.md)
26-
* [Binary Tree](binary_tree/README.md)
27-
* [Circularly Linked Lists](circularly_linked_list/README.md)
28-
* [Doubly Linked Lists](doubly_linked_list/README.md)
29-
* [Integers](integers/README.md)
30-
* [Matrices](multi_dimensional_arrays/README.md)
31-
* [N-ary Tree](n_ary_tree/README.md)
32-
* [Queues](queues/README.md)
33-
* [Singly Linked Lists](singly_linked_lists/README.md)
34-
* [Stacks](stacks/README.md)
35-
* [Strings](strings/README.md)
36-
* [Trie](trie/README.md)
11+
* [Arrays](arrays/)
12+
* [Binary Search](binary_search/)
13+
* [Binary Tree](binary_tree/)
14+
* [Circularly Linked Lists](circularly_linked_list/)
15+
* [Doubly Linked Lists](doubly_linked_list/)
16+
* [Integers](integers/)
17+
* [Math Problems](math_problems/)
18+
* [Matrices](multi_dimensional_arrays/)
19+
* [N-ary Tree](n_ary_tree/)
20+
* [Queues](queues/)
21+
* [Singly Linked Lists](singly_linked_lists/)
22+
* [Stacks](stacks/)
23+
* [Strings](strings/)
24+
* [Trie](trie/)
25+
26+
Each directory's problems and approaches are documented as doc comments directly in the corresponding `.py` files.
3727

3828
## Project Setup
3929

‎arrays/check_double.py‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
"""Check Double.
1+
from typing import List
22

3-
Given an array arr of integers, check if there exist two integers N and M such that N is the double of M (i.e.
4-
N = 2 * M). More formally, check if there exist two indices i and j such that i != j and arr[i] == 2 * arr[j].
53

6-
Example: `arr = [10, 2, 5, 3]` -> `True` (`N = 10` is the double of `M = 5`, since `10 = 2 * 5`)
7-
"""
4+
def check_double(arr: List[int]) -> bool:
5+
"""Check Double.
86
9-
from typing import List
7+
Given an array arr of integers, check if there exist two integers N and M such that N is the double of M (i.e.
8+
N = 2 * M). More formally, check if there exist two indices i and j such that i != j and arr[i] == 2 * arr[j].
109
10+
Example: `arr = [10, 2, 5, 3]` -> `True` (`N = 10` is the double of `M = 5`, since `10 = 2 * 5`)
1111
12-
def check_double(arr: List[int]) -> bool:
13-
"""Track seen values in a set and check for a value's double or half on each pass."""
12+
Track seen values in a set and check for a value's double or half on each pass.
13+
"""
1414
elements = set()
1515

1616
for num in arr:

‎arrays/container_with_max_area.py‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
"""Container With Max Area.
2-
3-
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai), n vertical
4-
lines are drawn such that the two endpoints of line i are at (i, ai) and (i, 0). Find two lines that, together
5-
with the x-axis, form a container holding the most water.
6-
"""
7-
81
from typing import List
92

103

114
def container_with_max_area(height: List[int]) -> int:
12-
"""Two-pointer sweep inward from both ends, tracking the largest area seen."""
5+
"""Container With Max Area.
6+
7+
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai), n vertical
8+
lines are drawn such that the two endpoints of line i are at (i, ai) and (i, 0). Find two lines that, together
9+
with the x-axis, form a container holding the most water.
10+
11+
Two-pointer sweep inward from both ends, tracking the largest area seen.
12+
"""
1313
length = len(height)
1414
left = 0
1515
right = length - 1

‎arrays/count_elements.py‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
"""Count Elements.
2-
3-
Given an integer array arr, count how many elements x there are such that x + 1 is also in arr. If there are
4-
duplicates in arr, count them separately.
5-
"""
6-
71
from typing import List
82

93

104
def count_elements(arr: List[int]) -> int:
11-
"""Build a set of values, then count elements whose successor is also present."""
5+
"""Count Elements.
6+
7+
Given an integer array arr, count how many elements x there are such that x + 1 is also in arr. If there are
8+
duplicates in arr, count them separately.
9+
10+
Build a set of values, then count elements whose successor is also present.
11+
"""
1212
elements = set()
1313
counter = 0
1414

‎arrays/duplicate_zeros.py‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
"""Duplicate Zeros.
1+
from typing import List
22

3-
Duplicate the zeros in the supplied array. Excess values should be discarded so that the array remains the same
4-
size.
53

6-
Example: `[1, 0, 2, 3, 0, 4, 5, 6]` -> `[1, 0, 0, 2, 3, 0, 0, 4]`
4+
def duplicate_zeros(arr: List[int]) -> List[int]:
5+
"""Duplicate Zeros.
76
8-
Time: O(N), Space: O(N)
9-
"""
7+
Duplicate the zeros in the supplied array. Excess values should be discarded so that the array remains the same
8+
size.
109
11-
from typing import List
10+
Example: `[1, 0, 2, 3, 0, 4, 5, 6]` -> `[1, 0, 0, 2, 3, 0, 0, 4]`
1211
12+
Time: O(N), Space: O(N)
1313
14-
def duplicate_zeros(arr: List[int]) -> List[int]:
15-
"""Build a shifted stack of values with zeros duplicated, then write it back in place."""
14+
Build a shifted stack of values with zeros duplicated, then write it back in place.
15+
"""
1616
stack = []
1717
index = 0
1818
length = len(arr)

‎arrays/find_index_largest_number.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
"""Find Index of Largest Number.
2-
3-
Find the index of the largest number in a list. Return -1 if the list is empty.
4-
"""
5-
61
from typing import List
72

83

94
def find_index_largest_number(numbers: List[int]) -> int:
10-
"""Single pass tracking the index of the largest value seen so far."""
5+
"""Find Index of Largest Number.
6+
7+
Find the index of the largest number in a list. Return -1 if the list is empty.
8+
9+
Single pass tracking the index of the largest value seen so far.
10+
"""
1111
if not numbers:
1212
return -1
1313

‎arrays/find_max_consecutive_ones.py‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
"""Find Max Consecutive Ones.
1+
from typing import List
22

3-
You are given a binary array nums; return the maximum number of consecutive 1's in the array.
43

5-
Example: `nums = [1, 1, 0, 1, 1, 1]` -> `3`
6-
Example: `nums = [1, 0, 1, 1, 0, 1]` -> `2`
7-
"""
4+
def find_max_consecutive_ones(nums: List[int]) -> int:
5+
"""Find Max Consecutive Ones.
86
9-
from typing import List
7+
You are given a binary array nums; return the maximum number of consecutive 1's in the array.
108
9+
Example: `nums = [1, 1, 0, 1, 1, 1]` -> `3`
10+
Example: `nums = [1, 0, 1, 1, 0, 1]` -> `2`
1111
12-
def find_max_consecutive_ones(nums: List[int]) -> int:
13-
"""Single pass tracking a running streak of 1s and the best streak seen."""
12+
Single pass tracking a running streak of 1s and the best streak seen.
13+
"""
1414
max_ones = 0
1515

1616
if not nums:

‎arrays/find_max_consecutive_ones_with_flip.py‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
"""Find Max Consecutive Ones With One Flip.
1+
from typing import List
22

3-
Given a binary array, find the maximum number of consecutive 1s in this array if you can flip at most one 0.
43

5-
Example: `[1, 0, 1, 1, 0]` -> `4` (flipping the first zero yields a run of four consecutive 1s)
6-
"""
4+
def find_max_consecutive_ones_with_flip(nums: List[int]) -> int:
5+
"""Find Max Consecutive Ones With One Flip.
76
8-
from typing import List
7+
Given a binary array, find the maximum number of consecutive 1s in this array if you can flip at most one 0.
98
9+
Example: `[1, 0, 1, 1, 0]` -> `4` (flipping the first zero yields a run of four consecutive 1s)
1010
11-
def find_max_consecutive_ones_with_flip(nums: List[int]) -> int:
12-
"""Single pass tracking the most recent flipped zero to extend the current run."""
11+
Single pass tracking the most recent flipped zero to extend the current run.
12+
"""
1313
zero = -1
1414
ones = 0
1515
highest = 0

0 commit comments

Comments
 (0)