{{ message }}

Instantly share code, notes, and snippets.

# Harris Rasheed h2rashee

Last active Jan 24, 2022
Given an organization structure, find the employee with the highest average rating (including their subordinates)
View employee_rating.py
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
 ''' A(3) B(3) C(4) D(1) E(2) ''' max_avg_rating = 0 max_avg_employee = None
Last active May 7, 2020
Datadog Take Home Assignment
View Makefile
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
Created Apr 22, 2020
Find the shortest path in a graph (distance and nodes)
View shortest_path.py
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],
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
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:
Last active May 21, 2020
Tic Tac Toe
View tic_tac_toe.py
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'
Last active Apr 20, 2020
Given an encrypted message string, determine the possible valid strings could match the message.
View decipher.py
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
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
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":
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
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
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
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
Last active Mar 4, 2020
Given a list, determine if the list is monotonic
View monotonic.py
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