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 Node: | |
def __init__(self, val = None): | |
self.left = None | |
self.right = None | |
self.val = val | |
self.end = False | |
class TrieMap: | |
def __init__(self): | |
self.root = Node() |
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 Node: | |
def __init__(self): | |
self.child = {} | |
self.end = False | |
class Trie: | |
def __init__(self): | |
self.root = Node() | |
def insert(self, 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
from collections import defaultdict | |
def radical(n): | |
primes = [True] * (n + 1) | |
primes[0] = primes[1] = False | |
for i in range(n + 1): | |
if primes[i]: | |
j = 2 | |
while i * j <= n: | |
primes[i * j] = False |
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 inverse(x, f, k = 15): | |
beg = 0 | |
end = 1 | |
while f(end) < x: | |
beg += 1 | |
end += 1 | |
while k: | |
mid = (beg + end) / 2 | |
if f(mid) > x: | |
end = mid |
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 genSparse(arr): | |
n = len(arr) | |
k = len("{:b}".format(n)) | |
table = [[float('inf')] * k for _ in range(n)] | |
for l in range(k): | |
for i in range(n): | |
if l == 0: | |
table[i][l] = arr[i] | |
else: | |
a = table[i][l - 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
class Node: | |
def __init__(self, start, end, min = float('inf')): | |
self.start = start | |
self.end = end | |
self.left = None | |
self.right = None | |
self.min = min | |
class SegTree: | |
def __init__(self, nums): |
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 Node: | |
def __init__(self, val = None, ctr = 1, left = None, right = None): | |
self.val = val | |
self.ctr = ctr | |
self.left = left | |
self.right = right | |
class BST: | |
def __init__(self): | |
self.root = 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
import math | |
def mobius(n): | |
ctr = 0 | |
k = int(math.sqrt(n)) + 1 | |
primes = [True] * k | |
primes[0], primes[1] = False, False | |
for i in range(k): | |
if primes[i]: | |
j = 2 |
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 Solution: | |
def minScore(self, values: List[int], n, used, usedctr) -> int: | |
if usedctr == n - 2: | |
return 0 | |
if used in self.cache: | |
return self.cache[used] | |
minScore = float('inf') | |
for i in range(n): | |
if not used & (1 << i + 1): | |
l = (n + i - 1) % n |
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
#include <stdio.h> | |
void main() | |
{ | |
int n = 10; | |
int hollow = 1; | |
int isSpace; | |
printf("Edge length? "); | |
scanf("%d", &n); | |
printf("Is Hollow?\n 0. No\n 1. Yes\n"); |