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
# coding:UTF-8 | |
import sys | |
import traceback | |
def a(): | |
print("a") | |
b() | |
def b(): |
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
# Python . operator search order | |
# 1. if magic methods are used implicitly, those methods on object's type are used | |
# 2. __getattributes__(self, attr) | |
# 3. object's type's __dict__ and it's a data descriptor, return it | |
# 4. object's __dict__ and it's a data descriptor, return it | |
# 5. object's __dict__ then object's type's __dict__ | |
# 6. __getattr__ | |
# 7. raise AttributeError |
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
#coding:UTF-8 | |
from math import inf, floor | |
from time import time | |
from random import randint | |
def linear_find_peak_1d(l, start, end): | |
minus_inf = -1 * inf | |
l = [minus_inf] + l[start:end] + [minus_inf] | |
for i in range(1, len(l)+1): |
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
#coding:UTF-8 | |
s1 = "my name is Hulk" | |
s2 = "my name is Iron man" | |
s3 = "your job is save the word" | |
from collections import defaultdict | |
import re | |
import math | |
from string import whitespace, punctuation, ascii_uppercase |
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
#codint:UTF-8 | |
def insertion_sort(l): | |
if len(l) <= 1: | |
return l | |
for i in range(1, len(l)): | |
key = l[i] | |
for j in reversed(range(0, i)): | |
c = l[j] | |
if c > key: |
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
#coding:UTF-8 | |
import math | |
def merge_sort(l): | |
if len(l) <= 1: | |
return l | |
mid_idx = (len(l)-0)//2 |
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
#coding:UTF-8 | |
def heapify(arr, i): | |
# O(lgn) | |
left_idx = 2*i+1 | |
if left_idx >= len(arr): | |
return | |
right_idx = left_idx + 1 | |
if right_idx >= len(arr): | |
left = arr[left_idx] |
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
#coding:UTF-8 | |
''' | |
notes on R5 | |
What is a data structure? | |
Algorithms for you to query update store information | |
BST | |
query: |
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
#coding:UTF-8 | |
from random import randint | |
from math import inf | |
''' | |
running time: O(n+k) | |
''' | |
def counting_sort(arr, n, k, key=lambda x: x): |
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
#coding:UTF-8 | |
from random import randint | |
from functools import partial | |
from counting_sort import counting_sort | |
''' | |
for simplicity: use base 10 | |
b - base | |
k - range of values of keys of the input |