This file contains hidden or 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 heapq | |
class Node: # Trie node | |
def __init__(self, val=""): | |
self.mem = [None] * 26 | |
self.count = 0 | |
self.val = val | |
def register_word(root, word): | |
node = root |
This file contains hidden or 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 EnhancedLinkedListNode: | |
def __init__(self, a, b, c): | |
self.a = a | |
self.b = b | |
self.c = c | |
self.next = None | |
self.prev = None | |
def remove(self): | |
if self.prev: |
This file contains hidden or 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 EnhancedLinkedListNode: | |
def __init__(self, a, b, c): | |
self.a = a | |
self.b = b | |
self.c = c | |
self.next = None | |
self.prev = None | |
def remove(self): | |
if self.prev: |
This file contains hidden or 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
""" | |
Difference between height of left and right childs has to be <=1 | |
""" | |
class AVLTreeNode: | |
def __init__(self, val, parent=None): | |
self.val = val | |
self.left = None | |
self.right = None |
This file contains hidden or 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 selection_sort(arr): | |
""" | |
Is named selection sort, because we are selecting smallest element each time and putting it as next | |
Time Complexity - O(N**2) | |
Space Complexity - O(1) | |
12.471 seconds for 10_000 numbers | |
""" | |
t = mn = 0 | |
for i in range(len(arr)): | |
mn = i |
This file contains hidden or 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 Checker: | |
@staticmethod | |
def is_this_type(expr): | |
raise NotImplementedError() | |
def does_match(self, value): | |
raise NotImplementedError() | |
class NameChecker(Checker): |
This file contains hidden or 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
# Definition for a binary tree node. | |
# class TreeNode: | |
# def __init__(self, x): | |
# self.val = x | |
# self.left = None | |
# self.right = None | |
class BSTIterator: | |
def __init__(self, root: TreeNode): |
This file contains hidden or 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
$PROMPT='{env_name:{} }{BOLD_GREEN}{user}@{hostname}{BOLD_BLUE} {cwd}{branch_color}{curr_branch: {}}{NO_COLOR} {BOLD_BLUE}\n{prompt_end}{NO_COLOR} ' |
This file contains hidden or 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 java.awt.image.BufferedImage; | |
import java.awt.image.DataBufferByte; | |
import java.io.File; | |
import java.io.IOException; | |
import javax.imageio.ImageIO; | |
public class NergativeImage { | |
public static BufferedImage saveImageFromPixels(int[][][] pixels, String name, String format, int width, int height, int type) { | |
BufferedImage temp = new BufferedImage(width, height, type); |
This file contains hidden or 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 task90(M, N, A, B, cords): | |
massive = [["*" if any((cord[0]==x and cord[1]==y) | |
or (x in range(cord[0]-A+1, cord[0]+1) and y in range(cord[1]-B+1, cord[1]+1)) | |
or (x in range(M-A+1, M+1)) | |
or (y in range(N-B+1, N+1)) | |
for cord in cords) else "_" for x in range(M)] for y in range(N)] | |
# print(*massive, sep = "\n") # Uncomment this for visualization | |
res = 0 | |
for row in massive: | |
for elem in row: |