Skip to content

Instantly share code, notes, and snippets.

View wilfreddesert's full-sized avatar

wilfreddesert

View GitHub Profile
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
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)
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])
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:
def is_balanced(exp: AnyStr) -> bool:
"""
Time Complexity: O(n)
Space complexity: O(n)
>>> s = "()[]{}"
>>> is_balanced(s)
True
>>> s = "([)]"
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)
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():
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)
from math import log2
import pytest
from binary_search import binary_search
class CounterElNumber:
_lt_global_counter = 0
_eq_global_counter = 0
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_