Skip to content

Instantly share code, notes, and snippets.

Avatar

Harris Rasheed h2rashee

View GitHub Profile
@h2rashee
h2rashee / employee_rating.py
Last active Jan 24, 2022
Given an organization structure, find the employee with the highest average rating (including their subordinates)
View employee_rating.py
'''
A(3)
B(3) C(4)
D(1) E(2)
'''
max_avg_rating = 0
max_avg_employee = None
@h2rashee
h2rashee / Makefile
Last active May 7, 2020
Datadog Take Home Assignment
View Makefile
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
@h2rashee
h2rashee / shortest_path.py
Created Apr 22, 2020
Find the shortest path in a graph (distance and nodes)
View shortest_path.py
# 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],
@h2rashee
h2rashee / concurrent.py
Last active Apr 25, 2020
Given a list of values, a function and the amount of concurrency to work with, apply the function so that it processes the function at the same time instead of blocking
View concurrent.py
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:
View tic_tac_toe.py
import random
ROWS = 3
COLS = 3
EMPTY = '-'
USER_MOVE = 'X'
AI_MOVE = 'O'
@h2rashee
h2rashee / decipher.py
Last active Apr 20, 2020
Given an encrypted message string, determine the possible valid strings could match the message.
View decipher.py
import requests
GARBLED_CHAR = '?'
class Trie:
def __init__(self):
self.children = dict()
self.is_word = False
@h2rashee
h2rashee / stock_exchange.py
Created Mar 6, 2020
Given a stream of buy/sell orders on an exchange, execute the trades favouring the best possible outcome for the trades in order and report the number of executed trade units.
View stock_exchange.py
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":
@h2rashee
h2rashee / trie.py
Created Mar 3, 2020
Given a word, find its index location from a list. Data structure of your choice and fuzzy matching to be supported (one character off is possible)
View trie.py
# 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
@h2rashee
h2rashee / paran_matching.py
Created Feb 25, 2020
Given a string with parantheses, return the number of parantheses needed to ensure there are enough matching.
View paran_matching.py
# (()) -> 0
# ))(( -> 4
# ()() -> 0
# (())) -> 1
# ()())( -> 2
def find_num_missing_parans(inp):
i = 0
j = 1
res = 0
@h2rashee
h2rashee / monotonic.py
Last active Mar 4, 2020
Given a list, determine if the list is monotonic
View monotonic.py
# 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