[pre-commit.ci] pre-commit autoupdate (#11322)

* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.2.2 → v0.3.2](https://github.com/astral-sh/ruff-pre-commit/compare/v0.2.2...v0.3.2)
- [github.com/pre-commit/mirrors-mypy: v1.8.0 → v1.9.0](https://github.com/pre-commit/mirrors-mypy/compare/v1.8.0...v1.9.0)

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
pre-commit-ci[bot]
2024-03-13 07:52:41 +01:00
committed by GitHub
parent 5f95d6f805
commit bc8df6de31
297 changed files with 488 additions and 285 deletions

View File

@ -6,6 +6,7 @@ elements whose sum is equal to req_sum.
https://practice.geeksforgeeks.org/problems/count-pairs-with-given-sum5022/0
"""
from itertools import combinations

View File

@ -1,15 +1,16 @@
"""
Sparse table is a data structure that allows answering range queries on
a static number list, i.e. the elements do not change throughout all the queries.
Sparse table is a data structure that allows answering range queries on
a static number list, i.e. the elements do not change throughout all the queries.
The implementation below will solve the problem of Range Minimum Query:
Finding the minimum value of a subset [L..R] of a static number list.
The implementation below will solve the problem of Range Minimum Query:
Finding the minimum value of a subset [L..R] of a static number list.
Overall time complexity: O(nlogn)
Overall space complexity: O(nlogn)
Overall time complexity: O(nlogn)
Overall space complexity: O(nlogn)
Wikipedia link: https://en.wikipedia.org/wiki/Range_minimum_query
Wikipedia link: https://en.wikipedia.org/wiki/Range_minimum_query
"""
from math import log2

View File

@ -3,6 +3,7 @@ Please do not modify this file! It is published at https://norvig.com/sudoku.ht
only minimal changes to work with modern versions of Python. If you have improvements,
please make them in a separate file.
"""
import random
import time

View File

@ -5,6 +5,7 @@ python3 -m doctest -v avl_tree.py
For testing run:
python avl_tree.py
"""
from __future__ import annotations
import math

View File

@ -88,6 +88,7 @@ True
>>> not t
True
"""
from __future__ import annotations
from collections.abc import Iterable, Iterator

View File

@ -7,6 +7,7 @@ python -m unittest binary_search_tree_recursive.py
To run an example:
python binary_search_tree_recursive.py
"""
from __future__ import annotations
import unittest

View File

@ -8,7 +8,6 @@ Python implementation:
frames that could be in memory is `n`
"""
from __future__ import annotations
from collections.abc import Iterator

View File

@ -2,6 +2,7 @@
The diameter/width of a tree is defined as the number of nodes on the longest path
between two end nodes.
"""
from __future__ import annotations
from dataclasses import dataclass

View File

@ -10,6 +10,7 @@ https://www.geeksforgeeks.org/flatten-a-binary-tree-into-linked-list
Author: Arunkumar A
Date: 04/09/2023
"""
from __future__ import annotations

View File

@ -9,6 +9,7 @@ https://bit.ly/46uB0a2
Author : Arunkumar
Date : 14th October 2023
"""
from __future__ import annotations
from collections.abc import Iterator

View File

@ -13,6 +13,7 @@ If n is the number of nodes in the tree then:
Runtime: O(n)
Space: O(1)
"""
from __future__ import annotations
from collections.abc import Iterator

View File

@ -3,6 +3,7 @@ Is a binary tree a sum tree where the value of every non-leaf node is equal to t
of the values of its left and right subtrees?
https://www.geeksforgeeks.org/check-if-a-given-binary-tree-is-sumtree
"""
from __future__ import annotations
from collections.abc import Iterator

View File

@ -5,6 +5,7 @@ The rule for merging is that if two nodes overlap, then put the value sum of
both nodes to the new value of the merged node. Otherwise, the NOT null node
will be used as the node of new tree.
"""
from __future__ import annotations

View File

@ -3,6 +3,7 @@ Given the root of a binary tree, mirror the tree, and return its root.
Leetcode problem reference: https://leetcode.com/problems/mirror-binary-tree/
"""
from __future__ import annotations
from collections.abc import Iterator

View File

@ -35,6 +35,7 @@ https://www.geeksforgeeks.org/segment-tree-efficient-implementation/
>>> st.query(0, 2)
[1, 2, 3]
"""
from __future__ import annotations
from collections.abc import Callable

View File

@ -6,6 +6,7 @@ We will use the formula: t(n) = SUMMATION(i = 1 to n)t(i-1)t(n-i)
Further details at Wikipedia: https://en.wikipedia.org/wiki/Catalan_number
"""
"""
Our Contribution:
Basically we Create the 2 function:

View File

@ -2,6 +2,7 @@
psf/black : true
ruff : passed
"""
from __future__ import annotations
from collections.abc import Iterator

View File

@ -3,6 +3,7 @@ Segment_tree creates a segment tree with a given array and function,
allowing queries to be done later in log(N) time
function takes 2 values and returns a same type value
"""
from collections.abc import Sequence
from queue import Queue

View File

@ -4,6 +4,7 @@ Given the root of a binary tree, check whether it is a mirror of itself
Leetcode reference: https://leetcode.com/problems/symmetric-tree/
"""
from __future__ import annotations
from dataclasses import dataclass

View File

@ -7,6 +7,7 @@ such as the with segment trees or fenwick trees. You can read more about them he
2. https://www.youtube.com/watch?v=4aSv9PcecDw&t=811s
3. https://www.youtube.com/watch?v=CybAgVF-MMc&t=1178s
"""
from __future__ import annotations
test_array = [2, 1, 4, 5, 6, 0, 8, 9, 1, 2, 0, 6, 4, 2, 0, 6, 5, 3, 2, 7]

View File

@ -1,6 +1,6 @@
"""
Disjoint set.
Reference: https://en.wikipedia.org/wiki/Disjoint-set_data_structure
Disjoint set.
Reference: https://en.wikipedia.org/wiki/Disjoint-set_data_structure
"""

View File

@ -58,6 +58,7 @@ The probability decreases with the number of bits in the bitarray.
>>> bloom.bitstring
'01100101'
"""
from hashlib import md5, sha256
HASH_FUNCTIONS = (sha256, md5)

View File

@ -11,6 +11,7 @@ Where hash1() and hash2() are hash functions and TABLE_SIZE is size of hash tabl
Reference: https://en.wikipedia.org/wiki/Double_hashing
"""
from .hash_table import HashTable
from .number_theory.prime_numbers import is_prime, next_prime

View File

@ -7,6 +7,7 @@ Another hash map implementation, with a good explanation.
Modern Dictionaries by Raymond Hettinger
https://www.youtube.com/watch?v=p33CVV29OG8
"""
from collections.abc import Iterator, MutableMapping
from dataclasses import dataclass
from typing import Generic, TypeVar

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python3
"""
module to operations with prime numbers
module to operations with prime numbers
"""
import math

View File

@ -5,6 +5,7 @@ Nodes contain data and also may link to other nodes:
head node gives us access of the complete list
- Last node: points to null
"""
from __future__ import annotations
from typing import Any

View File

@ -1,6 +1,7 @@
"""
Algorithm that merges two sorted linked lists into one sorted linked list.
"""
from __future__ import annotations
from collections.abc import Iterable, Iterator

View File

@ -2,6 +2,7 @@
Based on "Skip Lists: A Probabilistic Alternative to Balanced Trees" by William Pugh
https://epaperpress.com/sortsearch/download/skiplist.pdf
"""
from __future__ import annotations
from random import random

View File

@ -1,6 +1,7 @@
"""
Implementation of double ended queue.
"""
from __future__ import annotations
from collections.abc import Iterable

View File

@ -1,4 +1,5 @@
""" A Queue using a linked list like structure """
"""A Queue using a linked list like structure"""
from __future__ import annotations
from collections.abc import Iterator

View File

@ -1,4 +1,5 @@
"""Queue represented by a pseudo stack (represented by a list with pop and append)"""
from typing import Any

View File

@ -29,6 +29,7 @@ RULE 5: When the entire infix expression has been scanned, the value left on
NOTE: It only works with whole numbers.
"""
__author__ = "Alexander Joslin"
import operator as op

View File

@ -1,4 +1,5 @@
""" A Stack using a linked list like structure """
"""A Stack using a linked list like structure"""
from __future__ import annotations
from collections.abc import Iterator