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
run: | |
python3 main.py $(input_file) | |
test: | |
python3 main_test.py -v -b | |
format: | |
/Users/harrisrasheed/Library/Python/2.7/lib/python/site-packages/pycodestyle.py *.py --max-line-length=100 |
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
# Shortest Path | |
# G = [][] | |
# G[i][j] is the distance from i to j, and if G[i][j] < 0 means they are not connected. | |
# node ids ranging from 0 to len(G)-1 | |
# src, dst, return the shortest distance. | |
# revise it so that we can get one shortest path [src, node1, node2.... dst] | |
G=[ | |
[0, 2, -1 , 1, 7, -1], | |
[-1, 0, 3, 5, -1, -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
from multiprocessing import Pool | |
def fn(x): | |
return x+1 | |
def solution(vals, concurrency=1): | |
if concurrency < 1: | |
raise Exception('Concurrency value invalid') | |
with Pool(concurrency) as p: |
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 random | |
ROWS = 3 | |
COLS = 3 | |
EMPTY = '-' | |
USER_MOVE = 'X' | |
AI_MOVE = 'O' |
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 requests | |
GARBLED_CHAR = '?' | |
class Trie: | |
def __init__(self): | |
self.children = dict() | |
self.is_word = 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 order_book(orders): | |
# Ordered in descending order | |
buy_list = [] | |
# Ordered in ascending order | |
sell_list = [] | |
num_executed = 0 | |
for order in orders: | |
if order[2] == "buy": |
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
# dictionary = ["foo","bar","bat"] | |
# getIndex("foo") => 0 | |
# getIndex("bar") => 1 | |
# getIndex("bat") => 2 | |
# getIndex("fox") => 0 | |
# getIndex("fxx") => -1 | |
# getIndex("fo") => -1 | |
# getIndex("fooo") => -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
# (()) -> 0 | |
# ))(( -> 4 | |
# ()() -> 0 | |
# (())) -> 1 | |
# ()())( -> 2 | |
def find_num_missing_parans(inp): | |
i = 0 | |
j = 1 | |
res = 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
# 1, 2, 3, 4, 5 -> True | |
# 64, 32, 16, 8 -> True | |
# 1, 1, 2, 3, 5 -> True | |
# 10, 20, 15 -> False | |
# 0, 0, 0, 0 -> True | |
# 1 -> True | |
# -> True | |
def is_monotonic(nums): | |
is_ascending = 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
# International prefixes is a vague statement. Does that mean '+'' is allowed? Not clarified so assuming not. | |
# Notes on possible improvements: | |
# - Can create an inheritable/extensible method structure to support any piece's | |
# possible movements given a current position and a board instead of the current hard-coded methods | |
# The complexity of this solution depends on the size of the board | |
# and the length of the phone number being generated | |
def get_next_bishop_positions(x, y, x_lim, y_lim): |