This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OnlyProductInteger: | |
def __init__(self, value): | |
self._value = value | |
def __str__(self): | |
return str(self._value) | |
def __eq__(self, other): | |
return self._value == other._value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def divisible(begin, end): | |
""" | |
:param begin: int, positive integer | |
:param end: int, positive integer | |
:return: str, string of space separated integers | |
Examples of usage: | |
>>> divisible(1, 10) | |
'7' | |
>>> divisible(1, 17) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Vector: | |
""" | |
Class Vector is n-dimensional geometry vector. | |
Examples of usage: | |
>>> a = Vector([1, 2, 3, 4]) | |
>>> b = Vector([0, 1, -1, -4]) | |
>>> a | |
Vector([1, 2, 3, 4]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LRUCache: | |
""" | |
https://en.wikipedia.org/wiki/Cache_replacement_policies#Least_recently_used_(LRU) | |
""" | |
def __init__(self, maxsize: int = 16) -> None: | |
self.cache = {} | |
self.maxsize = maxsize | |
def put(self, key: Hashable, value: Any) -> None: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def is_balanced(exp: AnyStr) -> bool: | |
""" | |
Time Complexity: O(n) | |
Space complexity: O(n) | |
>>> s = "()[]{}" | |
>>> is_balanced(s) | |
True | |
>>> s = "([)]" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def nth_element(array: List[Real], k: Real) -> Real: | |
""" | |
Time Complexity: O(n) | |
Space Complexity: O(1) | |
>>> nth_element([1, 2, 3], 3) | |
3 | |
>>> nth_element([-1, -2, 3], 2) | |
-1 | |
>>> nth_element([-1, -2, 3, 10], 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from hypothesis import given | |
from hypothesis.strategies import integers, lists, sampled_from | |
from merge_sort import merge_sort | |
lists = lists(integers(), min_size=0, max_size=1000) | |
def test_sorted(): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pytest | |
import random | |
@pytest.fixture | |
def make_rnd_gen(): | |
def _get_result(seed, mode): | |
# Hint: use pytest.fixture | |
if mode == 0: | |
return random.Random(seed).randint(-1000, 1000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import log2 | |
import pytest | |
from binary_search import binary_search | |
class CounterElNumber: | |
_lt_global_counter = 0 | |
_eq_global_counter = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LinkedListIterator: | |
def __init__(self, head): | |
self.current = head | |
def __next__(self): | |
try: | |
data = self.current.data | |
except AttributeError: | |
raise StopIteration | |
self.current = self.current.next_ |
NewerOlder