Skip to content

Commit 49233f4

Browse files
Merge branch 'master' into patch-2
2 parents 023dec3 + 9ea690e commit 49233f4

34 files changed

+1143
-76
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- run: sudo apt-get update && sudo apt-get install -y libhdf5-dev
13-
- uses: actions/checkout@v5
13+
- uses: actions/checkout@v6
1414
- uses: astral-sh/setup-uv@v7
1515
with:
1616
enable-cache: true
@@ -22,7 +22,8 @@ jobs:
2222
- run: uv sync --group=test
2323
- name: Run tests
2424
# TODO: #8818 Re-enable quantum tests
25-
run: uv run pytest
25+
run: uv run --with=pytest-run-parallel pytest
26+
--iterations=8 --parallel-threads=auto
2627
--ignore=computer_vision/cnn_classification.py
2728
--ignore=docs/conf.py
2829
--ignore=dynamic_programming/k_means_clustering_tensorflow.py

.github/workflows/devcontainer_ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
build:
1313
runs-on: ubuntu-latest
1414
steps:
15-
- uses: actions/checkout@v5
15+
- uses: actions/checkout@v6
1616
- uses: devcontainers/ci@v0.3
1717
with:
1818
push: never

.github/workflows/directory_writer.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
directory_writer:
77
runs-on: ubuntu-latest
88
steps:
9-
- uses: actions/checkout@v5
9+
- uses: actions/checkout@v6
1010
with:
1111
fetch-depth: 0
1212
- uses: actions/setup-python@v6

.github/workflows/project_euler.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
libxml2-dev libxslt-dev
2222
libhdf5-dev
2323
libopenblas-dev
24-
- uses: actions/checkout@v5
24+
- uses: actions/checkout@v6
2525
- uses: astral-sh/setup-uv@v7
2626
- uses: actions/setup-python@v6
2727
with:
@@ -39,7 +39,7 @@ jobs:
3939
libxml2-dev libxslt-dev
4040
libhdf5-dev
4141
libopenblas-dev
42-
- uses: actions/checkout@v5
42+
- uses: actions/checkout@v6
4343
- uses: astral-sh/setup-uv@v7
4444
- uses: actions/setup-python@v6
4545
with:

.github/workflows/ruff.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ jobs:
1111
ruff:
1212
runs-on: ubuntu-latest
1313
steps:
14-
- uses: actions/checkout@v5
14+
- uses: actions/checkout@v6
1515
- uses: astral-sh/setup-uv@v7
1616
- run: uvx ruff check --output-format=github .

.github/workflows/sphinx.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
libxml2-dev libxslt-dev
3333
libhdf5-dev
3434
libopenblas-dev
35-
- uses: actions/checkout@v5
35+
- uses: actions/checkout@v6
3636
- uses: astral-sh/setup-uv@v7
3737
- uses: actions/setup-python@v6
3838
with:

.pre-commit-config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ repos:
1414
- id: requirements-txt-fixer
1515

1616
- repo: https://github.com/MarcoGorelli/auto-walrus
17-
rev: 0.3.4
17+
rev: 0.4.1
1818
hooks:
1919
- id: auto-walrus
2020

2121
- repo: https://github.com/astral-sh/ruff-pre-commit
22-
rev: v0.13.3
22+
rev: v0.14.14
2323
hooks:
2424
- id: ruff-check
2525
- id: ruff-format
@@ -32,7 +32,7 @@ repos:
3232
- tomli
3333

3434
- repo: https://github.com/tox-dev/pyproject-fmt
35-
rev: v2.7.0
35+
rev: v2.12.1
3636
hooks:
3737
- id: pyproject-fmt
3838

@@ -50,7 +50,7 @@ repos:
5050
- id: validate-pyproject
5151

5252
- repo: https://github.com/pre-commit/mirrors-mypy
53-
rev: v1.18.2
53+
rev: v1.19.1
5454
hooks:
5555
- id: mypy
5656
args:

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ We want your work to be readable by others; therefore, we encourage you to note
159159
starting_value = int(input("Please enter a starting value: ").strip())
160160
```
161161

162-
The use of [Python type hints](https://docs.python.org/3/library/typing.html) is encouraged for function parameters and return values. Our automated testing will run [mypy](http://mypy-lang.org) so run that locally before making your submission.
162+
The use of [Python type hints](https://docs.python.org/3/library/typing.html) is encouraged for function parameters and return values. Our automated testing will run [mypy](https://mypy-lang.org) so run that locally before making your submission.
163163

164164
```python
165165
def sum_ab(a: int, b: int) -> int:

DIRECTORY.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@
398398
* [Minimum Squares To Represent A Number](dynamic_programming/minimum_squares_to_represent_a_number.py)
399399
* [Minimum Steps To One](dynamic_programming/minimum_steps_to_one.py)
400400
* [Minimum Tickets Cost](dynamic_programming/minimum_tickets_cost.py)
401+
* [Narcissistic Number](dynamic_programming/narcissistic_number.py)
401402
* [Optimal Binary Search Tree](dynamic_programming/optimal_binary_search_tree.py)
402403
* [Palindrome Partitioning](dynamic_programming/palindrome_partitioning.py)
403404
* [Range Sum Query](dynamic_programming/range_sum_query.py)
@@ -880,6 +881,7 @@
880881
* [Quine](other/quine.py)
881882
* [Scoring Algorithm](other/scoring_algorithm.py)
882883
* [Sdes](other/sdes.py)
884+
* [Sliding Window Maximum](other/sliding_window_maximum.py)
883885
* [Tower Of Hanoi](other/tower_of_hanoi.py)
884886
* [Word Search](other/word_search.py)
885887

backtracking/generate_parentheses_iterative.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
def generate_parentheses_iterative(length: int) -> list:
1+
def generate_parentheses_iterative(length: int) -> list[str]:
22
"""
33
Generate all valid combinations of parentheses (Iterative Approach).
44
55
The algorithm works as follows:
66
1. Initialize an empty list to store the combinations.
77
2. Initialize a stack to keep track of partial combinations.
8-
3. Start with empty string and push it onstack along with the counts of '(' and ')'.
8+
3. Start with empty string and push it on stack along with
9+
the counts of '(' and ')'.
910
4. While the stack is not empty:
1011
a. Pop a partial combination and its open and close counts from the stack.
1112
b. If the combination length is equal to 2*length, add it to the result.
@@ -34,8 +35,11 @@ def generate_parentheses_iterative(length: int) -> list:
3435
>>> generate_parentheses_iterative(0)
3536
['']
3637
"""
37-
result = []
38-
stack = []
38+
if length == 0:
39+
return [""]
40+
41+
result: list[str] = []
42+
stack: list[tuple[str, int, int]] = []
3943

4044
# Each element in stack is a tuple (current_combination, open_count, close_count)
4145
stack.append(("", 0, 0))
@@ -45,6 +49,7 @@ def generate_parentheses_iterative(length: int) -> list:
4549

4650
if len(current_combination) == 2 * length:
4751
result.append(current_combination)
52+
continue
4853

4954
if open_count < length:
5055
stack.append((current_combination + "(", open_count + 1, close_count))

0 commit comments

Comments
 (0)